diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 0c82d6cfe08..b90d97e0f02 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -21,7 +21,8 @@ A group action `G \times S \rightarrow S` is a functor from `G` to Sets. sage: import gc sage: _ = gc.collect() sage: A - ) failed: RuntimeError: This action acted on a set that became garbage collected> + ) failed: + RuntimeError: This action acted on a set that became garbage collected> To avoid garbage collection of the underlying set, it is sufficient to create a strong reference to it before the action is created. @@ -265,15 +266,17 @@ cdef class Action(Functor): sage: R = (ZZ['x'])['y'] sage: A = R.get_action(P,operator.mul,True) sage: A # indirect doctest - Right scalar multiplication by Univariate Polynomial Ring in x over - Rational Field on Univariate Polynomial Ring in y over Univariate - Polynomial Ring in x over Integer Ring + Right scalar multiplication + by Univariate Polynomial Ring in x over Rational Field + on Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Integer Ring In this example, the underlying set is the ring ``R``. This is the same as the left domain, which is different from the codomain of the action:: sage: A.codomain() - Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field sage: A.codomain() == R False sage: A.left_domain() is R @@ -294,7 +297,8 @@ cdef class Action(Functor): sage: import gc sage: _ = gc.collect() sage: A - ) failed: RuntimeError: This action acted on a set that became garbage collected> + ) failed: + RuntimeError: This action acted on a set that became garbage collected> """ S = self.US() if S is None: @@ -329,24 +333,28 @@ cdef class InverseAction(Action): EXAMPLES:: - sage: V = QQ^3 - sage: v = V((1, 2, 3)) + sage: V = QQ^3 # optional - sage.modules + sage: v = V((1, 2, 3)) # optional - sage.modules sage: cm = get_coercion_model() - 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 - Right inverse action by Rational Field on Vector space of dimension 3 over Rational Field - sage: (~a)(v, 1/3) + sage: a = cm.get_action(V, QQ, operator.mul) # optional - sage.modules + sage: a # optional - sage.modules + Right scalar multiplication by Rational Field + on Vector space of dimension 3 over Rational Field + sage: ~a # optional - sage.modules + Right inverse action by Rational Field + on Vector space of dimension 3 over Rational Field + sage: (~a)(v, 1/3) # optional - sage.modules (3, 6, 9) - 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 - Left inverse action by Rational Field on Vector space of dimension 3 over Rational Field - sage: (~b)(1/3, v) + sage: b = cm.get_action(QQ, V, operator.mul) # optional - sage.modules + sage: b # optional - sage.modules + Left scalar multiplication by Rational Field + on Vector space of dimension 3 over Rational Field + sage: ~b # optional - sage.modules + Left inverse action by Rational Field + on Vector space of dimension 3 over Rational Field + sage: (~b)(1/3, v) # optional - sage.modules (3, 6, 9) sage: c = cm.get_action(ZZ, list, operator.mul) @@ -390,11 +398,11 @@ cdef class InverseAction(Action): Check that this action can be pickled (:trac:`29031`):: - 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 + 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 True """ return (type(self), (self._action,)) @@ -434,8 +442,9 @@ cdef class PrecomposedAction(Action): 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: + Left scalar multiplication by Rational Field + on Abelian Group of all Formal Finite Sums over Rational Field + with precomposition on right by Coercion map: From: Abelian Group of all Formal Finite Sums over Integer Ring To: Abelian Group of all Formal Finite Sums over Rational Field """ @@ -542,8 +551,8 @@ cdef class ActionEndomorphism(Morphism): sage: A = ZZ['x'].get_action(QQ, self_on_left=False, op=operator.mul) sage: A - Left scalar multiplication by Rational Field on Univariate Polynomial - Ring in x over Integer Ring + Left scalar multiplication by Rational Field + on Univariate Polynomial Ring in x over Integer Ring sage: A(1/2) Action of 1/2 on Univariate Polynomial Ring in x over Integer Ring under Left scalar multiplication by Rational Field on Univariate diff --git a/src/sage/categories/additive_magmas.py b/src/sage/categories/additive_magmas.py index 8d2c46d0771..3f688577aff 100644 --- a/src/sage/categories/additive_magmas.py +++ b/src/sage/categories/additive_magmas.py @@ -33,7 +33,10 @@ class AdditiveMagmas(Category_singleton): sage: AdditiveMagmas().super_categories() [Category of sets] sage: AdditiveMagmas().all_super_categories() - [Category of additive magmas, Category of sets, Category of sets with partial maps, Category of objects] + [Category of additive magmas, + Category of sets, + Category of sets with partial maps, + Category of objects] The following axioms are defined by this category:: @@ -45,11 +48,11 @@ class AdditiveMagmas(Category_singleton): Category of additive commutative additive magmas sage: AdditiveMagmas().AdditiveUnital().AdditiveInverse() Category of additive inverse additive unital additive magmas - sage: AdditiveMagmas().AdditiveAssociative().AdditiveCommutative() + sage: C = AdditiveMagmas().AdditiveAssociative().AdditiveCommutative(); C Category of commutative additive semigroups - sage: AdditiveMagmas().AdditiveAssociative().AdditiveCommutative().AdditiveUnital() + sage: C.AdditiveUnital() Category of commutative additive monoids - sage: AdditiveMagmas().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().AdditiveInverse() + sage: C.AdditiveUnital().AdditiveInverse() Category of commutative additive groups TESTS:: @@ -112,9 +115,10 @@ def AdditiveCommutative(self): sage: AdditiveMagmas().AdditiveCommutative() Category of additive commutative additive magmas - sage: AdditiveMagmas().AdditiveAssociative().AdditiveUnital().AdditiveCommutative() + sage: C = AdditiveMagmas().AdditiveAssociative().AdditiveUnital() + sage: C.AdditiveCommutative() Category of commutative additive monoids - sage: _ is CommutativeAdditiveMonoids() + sage: C.AdditiveCommutative() is CommutativeAdditiveMonoids() True TESTS:: @@ -279,7 +283,7 @@ def addition_table(self, names='letters', elements=None): elements as lowercase ASCII letters. :: sage: R = IntegerModRing(5) - sage: R.addition_table() + sage: R.addition_table() # optional - sage.modules + a b c d e +---------- a| a b c d e @@ -294,8 +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') - sage: P + sage: P = R.addition_table(names='elements'); P # optional - 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 @@ -310,8 +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') - sage: T + sage: T = R.addition_table(names='digits'); T # optional - 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 @@ -331,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) + sage: S.addition_table(elements=elts) # optional - sage.modules + a b c d e f g +-------------- a| a b c d e f g @@ -351,8 +353,8 @@ def addition_table(self, names='letters', elements=None): representation. :: sage: T = IntegerModRing(12) - sage: elts=[0, 3, 6, 9] - sage: T.addition_table(names='elements', elements=elts) + sage: elts = [0, 3, 6, 9] + sage: T.addition_table(names='elements', elements=elts) # optional - sage.modules + 0 3 6 9 +-------- 0| 0 3 6 9 @@ -366,15 +368,15 @@ def addition_table(self, names='letters', elements=None): comprehensive documentation. :: sage: R = IntegerModRing(3) - sage: T = R.addition_table() - sage: T.column_keys() + sage: T = R.addition_table() # optional - sage.modules + sage: T.column_keys() # optional - sage.modules (0, 1, 2) - sage: sorted(T.translation().items()) + sage: sorted(T.translation().items()) # optional - sage.modules [('a', 0), ('b', 1), ('c', 2)] - sage: T.change_names(['x', 'y', 'z']) - sage: sorted(T.translation().items()) + sage: T.change_names(['x', 'y', 'z']) # optional - sage.modules + sage: sorted(T.translation().items()) # optional - sage.modules [('x', 0), ('y', 1), ('z', 2)] - sage: T + sage: T # optional - sage.modules + x y z +------ x| x y z @@ -471,16 +473,16 @@ def _add_(self, right): r""" EXAMPLES:: - sage: G5=GF(5); G8=GF(4,'x'); GG = G5.cartesian_product(G8) - sage: e = GG((G5(1),G8.primitive_element())); e + 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 (1, x) - sage: e+e + sage: e + e # optional - sage.rings.finite_rings (2, 0) - sage: e = groups.misc.AdditiveCyclic(8) - sage: x = e.cartesian_product(e)((e(1),e(2))) - sage: x + 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 (1, 2) - sage: 4*x + sage: 4 * x # optional - sage.rings.finite_rings (4, 0) """ return self.parent()._cartesian_product_of_elements( @@ -497,7 +499,8 @@ def extra_super_categories(self): [Category of magmatic algebras with basis over Rational Field] sage: AdditiveMagmas().Algebras(QQ).super_categories() - [Category of magmatic algebras with basis over Rational Field, Category of set algebras over Rational Field] + [Category of magmatic algebras with basis over Rational Field, + Category of set algebras over Rational Field] """ from sage.categories.magmatic_algebras import MagmaticAlgebras return [MagmaticAlgebras(self.base_ring()).WithBasis()] @@ -516,9 +519,10 @@ def algebra_generators(self): EXAMPLES:: 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) - sage: A.algebra_generators() + 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 Family (B[a], B[b], B[c], B[d]) .. TODO:: @@ -541,10 +545,11 @@ def product_on_basis(self, g1, g2): EXAMPLES:: 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) - sage: a,b,c,d = A.algebra_generators() - sage: a * d * b + 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 B[a + b + d] .. TODO:: @@ -580,10 +585,11 @@ def extra_super_categories(self): EXAMPLES:: - sage: AdditiveMagmas().AdditiveCommutative().Algebras(QQ).extra_super_categories() + sage: C = AdditiveMagmas().AdditiveCommutative().Algebras(QQ) + sage: C.extra_super_categories() [Category of commutative magmas] - sage: AdditiveMagmas().AdditiveCommutative().Algebras(QQ).super_categories() + sage: C.super_categories() [Category of additive magma algebras over Rational Field, Category of commutative magmas] """ @@ -718,10 +724,10 @@ def is_empty(self): EXAMPLES:: - sage: A = AdditiveAbelianGroup([3,3]) - sage: A in AdditiveMagmas() + sage: A = AdditiveAbelianGroup([3, 3]) # optional - sage.groups + sage: A in AdditiveMagmas() # optional - sage.groups True - sage: A.is_empty() + sage: A.is_empty() # optional - sage.groups False sage: B = CommutativeAdditiveMonoids().example() @@ -733,7 +739,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__ + sage: A.is_empty.__module__ # optional - sage.groups 'sage.categories.additive_magmas' sage: B.is_empty.__module__ 'sage.categories.additive_magmas' @@ -801,17 +807,17 @@ def _sub_(left, right): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b']) - sage: a,b = F.basis() - sage: a - b + sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # optional - sage.modules + sage: a, b = F.basis() # optional - sage.modules + sage: a - b # optional - sage.modules B['a'] - B['b'] TESTS: Check that :trac:`18275` is fixed:: - sage: C = GF(5).cartesian_product(GF(5)) - sage: C.one() - C.one() + sage: C = GF(5).cartesian_product(GF(5)) # optional - sage.rings.finite_rings + sage: C.one() - C.one() # optional - sage.rings.finite_rings (0, 0) """ return left + (-right) @@ -827,21 +833,21 @@ def __neg__(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b']) - sage: a,b = F.basis() - sage: - b + sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # optional - sage.modules + sage: a, b = F.basis() # optional - sage.modules + sage: -b # optional - sage.modules -B['b'] TESTS:: - 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 + 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 B[(0, 'a')] + 2*B[(1, 'a')] - 3*B[(1, 'b')] - sage: x.parent() is FF + sage: x.parent() is FF # optional - sage.modules True - sage: -x + sage: -x # optional - sage.modules -B[(0, 'a')] - 2*B[(1, 'a')] + 3*B[(1, 'b')] """ return self._neg_() @@ -911,14 +917,15 @@ def _neg_(self): EXAMPLES:: - sage: x = cartesian_product((GF(7)(2),17)) ; x + sage: x = cartesian_product((GF(7)(2), 17)); x # optional - sage.rings.finite_rings (2, 17) - sage: -x + sage: -x # optional - sage.rings.finite_rings (5, -17) TESTS:: - sage: x.parent() in AdditiveMagmas().AdditiveUnital().AdditiveInverse().CartesianProducts() + sage: C = AdditiveMagmas().AdditiveUnital().AdditiveInverse().CartesianProducts() + sage: x.parent() in C # optional - sage.rings.finite_rings True """ return self.parent()._cartesian_product_of_elements( @@ -947,7 +954,7 @@ def zero(self): EXAMPLES:: - sage: GF(8,'x').cartesian_product(GF(5)).zero() + sage: GF(8, 'x').cartesian_product(GF(5)).zero() # optional - sage.rings.finite_rings (0, 0) """ return self._cartesian_product_of_elements( @@ -964,7 +971,8 @@ def extra_super_categories(self): [Category of unital magmas] sage: C.super_categories() - [Category of unital algebras with basis over Rational Field, Category of additive magma algebras over Rational Field] + [Category of unital algebras with basis over Rational Field, + Category of additive magma algebras over Rational Field] """ from sage.categories.magmas import Magmas return [Magmas().Unital()] @@ -982,13 +990,14 @@ def one_basis(self): EXAMPLES:: 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) - sage: A.one_basis() + 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 0 - sage: A.one() + sage: A.one() # optional - sage.modules B[0] - sage: A(3) + sage: A(3) # optional - sage.modules 3*B[0] """ return self.basis().keys().zero() @@ -1007,17 +1016,17 @@ def zero(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat The subset algebra of {1, 2, 3} over Rational Field - sage: A.zero.__module__ + sage: A.zero.__module__ # optional - sage.combinat 'sage.categories.additive_magmas' - sage: A.zero() + sage: A.zero() # optional - sage.combinat 0 TESTS:: - sage: A.zero() is A.a_realization().zero() + sage: A.zero() is A.a_realization().zero() # optional - sage.combinat True - sage: A._test_zero() + sage: A._test_zero() # optional - sage.combinat """ return self.a_realization().zero() diff --git a/src/sage/categories/additive_semigroups.py b/src/sage/categories/additive_semigroups.py index 0527867154b..667e27eb1e9 100644 --- a/src/sage/categories/additive_semigroups.py +++ b/src/sage/categories/additive_semigroups.py @@ -150,9 +150,10 @@ def algebra_generators(self): EXAMPLES:: 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) - sage: A.algebra_generators() + 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 Family (B[a], B[b], B[c], B[d]) """ return self.basis().keys().additive_semigroup_generators().map(self.monomial) @@ -169,10 +170,11 @@ def product_on_basis(self, g1, g2): EXAMPLES:: 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) - sage: a,b,c,d = A.algebra_generators() - sage: b * d * c + 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 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 6bc26562b8e..3df85b07415 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 + sage: W = WeylGroup(["A", 4, 1]); W # optional - sage.combinat sage.groups Weyl Group of type ['A', 4, 1] (as a matrix group acting on the root space) - sage: W.category() + sage: W.category() # optional - 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]) - sage: W.special_node() + sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups + sage: W.special_node() # optional - sage.combinat sage.groups 0 """ return self.cartan_type().special_node() @@ -95,8 +95,9 @@ def affine_grassmannian_elements_of_given_length(self, k): EXAMPLES:: - sage: W = WeylGroup(['A',3,1]) - sage: [x.reduced_word() for x in W.affine_grassmannian_elements_of_given_length(3)] + sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups + sage: [x.reduced_word() # optional - sage.combinat sage.groups + ....: for x in W.affine_grassmannian_elements_of_given_length(3)] [[2, 1, 0], [3, 1, 0], [2, 3, 0]] .. SEEALSO:: @@ -136,14 +137,14 @@ def is_affine_grassmannian(self): EXAMPLES:: - sage: W = WeylGroup(['A',3,1]) - sage: w = W.from_reduced_word([2,1,0]) - sage: w.is_affine_grassmannian() + 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 True - sage: w = W.from_reduced_word([2,0]) - sage: w.is_affine_grassmannian() + sage: w = W.from_reduced_word([2,0]) # optional - sage.combinat sage.groups + sage: w.is_affine_grassmannian() # optional - sage.combinat sage.groups False - sage: W.one().is_affine_grassmannian() + sage: W.one().is_affine_grassmannian() # optional - sage.combinat sage.groups True """ D = self.descents() @@ -168,17 +169,17 @@ def affine_grassmannian_to_core(self): EXAMPLES:: - sage: W = WeylGroup(['A',2,1]) - sage: w = W.from_reduced_word([0,2,1,0]) - sage: la = w.affine_grassmannian_to_core(); la + 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 [4, 2] - sage: type(la) + sage: type(la) # optional - sage.combinat sage.groups - sage: la.to_grassmannian() == w + sage: la.to_grassmannian() == w # optional - sage.combinat sage.groups True - sage: w = W.from_reduced_word([0,2,1]) - sage: w.affine_grassmannian_to_core() + 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 Traceback (most recent call last): ... ValueError: this only works on type 'A' affine Grassmannian elements @@ -214,11 +215,11 @@ def affine_grassmannian_to_partition(self): EXAMPLES:: sage: k = 2 - sage: W = WeylGroup(['A',k,1]) - sage: w = W.from_reduced_word([0,2,1,0]) - sage: la = w.affine_grassmannian_to_partition(); la + 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 [2, 2] - sage: la.from_kbounded_to_grassmannian(k) == w + sage: la.from_kbounded_to_grassmannian(k) == w # optional - sage.combinat sage.groups 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 d2c64474d8e..9142a9b6e38 100644 --- a/src/sage/categories/algebra_functor.py +++ b/src/sage/categories/algebra_functor.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - 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 2beecea2ee4..3bea4f66f91 100644 --- a/src/sage/categories/algebra_ideals.py +++ b/src/sage/categories/algebra_ideals.py @@ -79,9 +79,10 @@ def super_categories(self): EXAMPLES:: 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')) - sage: C.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 [] """ diff --git a/src/sage/categories/algebra_modules.py b/src/sage/categories/algebra_modules.py index 46698060095..086b834f955 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')) + sage: AlgebraModules(FreeAlgebra(QQ, 2, 'a,b')) # optional - 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 253d64a2819..3b808b5d1b7 100644 --- a/src/sage/categories/algebras.py +++ b/src/sage/categories/algebras.py @@ -68,7 +68,7 @@ def __contains__(self, x): sage: QQ['x'] in Algebras(QQ) True - sage: QQ^3 in Algebras(QQ) + sage: QQ^3 in Algebras(QQ) # optional - sage.modules False sage: QQ['x'] in Algebras(CDF) False @@ -154,15 +154,15 @@ def _div_(self, y): EXAMPLES:: - sage: C = AlgebrasWithBasis(QQ).example() - sage: x = C(2); x + sage: C = AlgebrasWithBasis(QQ).example() # optional - sage.combinat + sage: x = C(2); x # optional - sage.combinat 2*B[word: ] - sage: y = C.algebra_generators().first(); y + sage: y = C.algebra_generators().first(); y # optional - sage.combinat B[word: a] - sage: y._div_(x) + sage: y._div_(x) # optional - sage.combinat 1/2*B[word: a] - sage: x._div_(y) + sage: x._div_(y) # optional - sage.combinat Traceback (most recent call last): ... ValueError: cannot invert self (= B[word: a]) diff --git a/src/sage/categories/algebras_with_basis.py b/src/sage/categories/algebras_with_basis.py index d2296873b59..e7762b50f24 100644 --- a/src/sage/categories/algebras_with_basis.py +++ b/src/sage/categories/algebras_with_basis.py @@ -33,35 +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 - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field + sage: A = C.example(); A # optional - sage.combinat + An example of an algebra with basis: + the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.category() + sage: A.category() # optional - sage.combinat Category of algebras with basis over Rational Field - sage: A.one_basis() + sage: A.one_basis() # optional - sage.combinat word: - sage: A.one() + sage: A.one() # optional - sage.combinat B[word: ] - sage: A.base_ring() + sage: A.base_ring() # optional - sage.combinat Rational Field - sage: A.basis().keys() + sage: A.basis().keys() # optional - sage.combinat Finite words over {'a', 'b', 'c'} - sage: (a,b,c) = A.algebra_generators() - sage: a^3, b^2 + sage: (a,b,c) = A.algebra_generators() # optional - sage.combinat + sage: a^3, b^2 # optional - sage.combinat (B[word: aaa], B[word: bb]) - sage: a*c*b + sage: a * c * b # optional - sage.combinat B[word: acb] - sage: A.product + sage: A.product # optional - sage.combinat - sage: A.product(a*b,b) + An example of an algebra with basis: + the free algebra on the generators ('a', 'b', 'c') over Rational Field> + sage: A.product(a * b, b) # optional - sage.combinat B[word: abb] - sage: TestSuite(A).run(verbose=True) + sage: TestSuite(A).run(verbose=True) # optional - sage.combinat running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_associativity() . . . pass @@ -91,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__ + sage: A.__class__ # optional - sage.combinat - sage: A.element_class + sage: A.element_class # optional - sage.combinat Please see the source code of `A` (with ``A??``) for how to @@ -110,13 +112,15 @@ def example(self, alphabet=('a','b','c')): EXAMPLES:: - sage: AlgebrasWithBasis(QQ).example() - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field + sage: AlgebrasWithBasis(QQ).example() # optional - sage.combinat + 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)) - An example of an algebra with basis: the free algebra on the generators (1, 2, 3) over Rational Field + sage: AlgebrasWithBasis(QQ).example((1,2,3)) # optional - sage.combinat + An example of an algebra with basis: + the free algebra on the generators (1, 2, 3) over Rational Field """ from sage.categories.examples.algebras_with_basis import Example return Example(self.base_ring(), alphabet) @@ -143,12 +147,12 @@ def hochschild_complex(self, M): EXAMPLES:: sage: R. = QQ[] - sage: A = algebras.DifferentialWeyl(R) - sage: H = A.hochschild_complex(A) + sage: A = algebras.DifferentialWeyl(R) # optional - sage.combinat + sage: H = A.hochschild_complex(A) # optional - sage.combinat - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: T = SGA.trivial_representation() - sage: H = SGA.hochschild_complex(T) + 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 """ from sage.homology.hochschild_complex import HochschildComplex return HochschildComplex(self, M) @@ -176,14 +180,14 @@ def __invert__(self): EXAMPLES:: - sage: C = AlgebrasWithBasis(QQ).example() - sage: x = C(2); x + sage: C = AlgebrasWithBasis(QQ).example() # optional - sage.combinat + sage: x = C(2); x # optional - sage.combinat 2*B[word: ] - sage: ~x + sage: ~x # optional - sage.combinat 1/2*B[word: ] - sage: a = C.algebra_generators().first(); a + sage: a = C.algebra_generators().first(); a # optional - sage.combinat B[word: a] - sage: ~a + sage: ~a # optional - sage.combinat Traceback (most recent call last): ... ValueError: cannot invert self (= B[word: a]) @@ -237,18 +241,20 @@ def one_from_cartesian_product_of_one_basis(self): EXAMPLES:: - 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() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + 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 word: - sage: B = cartesian_product((A, A, A)) - sage: B.one_from_cartesian_product_of_one_basis() + sage: B = cartesian_product((A, A, A)) # optional - sage.combinat + sage: B.one_from_cartesian_product_of_one_basis() # optional - sage.combinat B[(0, word: )] + B[(1, word: )] + B[(2, word: )] - sage: B.one() + sage: B.one() # optional - sage.combinat B[(0, word: )] + B[(1, word: )] + B[(2, word: )] - sage: cartesian_product([SymmetricGroupAlgebra(QQ, 3), SymmetricGroupAlgebra(QQ, 4)]).one() + sage: cartesian_product([SymmetricGroupAlgebra(QQ, 3), # optional - sage.combinat + ....: SymmetricGroupAlgebra(QQ, 4)]).one() B[(0, [1, 2, 3])] + B[(1, [1, 2, 3, 4])] """ return self.sum_of_monomials( zip( self._sets_keys(), (set.one_basis() for set in self._sets)) ) @@ -258,10 +264,11 @@ def one(self): """ TESTS:: - 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 = cartesian_product((A, A, A)) - sage: B.one() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + 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 B[(0, word: )] + B[(1, word: )] + B[(2, word: )] """ if all(hasattr(module, "one_basis") for module in self._sets): @@ -310,14 +317,15 @@ def one_basis(self): EXAMPLES:: - 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() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + 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 word: - sage: B = tensor((A, A, A)) - sage: B.one_basis() + sage: B = tensor((A, A, A)) # optional - sage.combinat + sage: B.one_basis() # optional - sage.combinat (word: , word: , word: ) - sage: B.one() + sage: B.one() # optional - sage.combinat B[word: ] # B[word: ] # B[word: ] """ # FIXME: this method should be conditionally defined, @@ -335,23 +343,25 @@ def product_on_basis(self, t1, t2): EXAMPLES:: - 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,b,c) = A.algebra_generators() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + 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: x = tensor( (a, b, c) ); x + sage: x = tensor((a, b, c)); x # optional - sage.combinat B[word: a] # B[word: b] # B[word: c] - sage: y = tensor( (c, b, a) ); y + sage: y = tensor((c, b, a)); y # optional - sage.combinat B[word: c] # B[word: b] # B[word: a] - sage: x*y + sage: x * y # optional - sage.combinat B[word: ac] # B[word: bb] # B[word: ca] - sage: x = tensor( ((a+2*b), c) ) ; x + sage: x = tensor(((a + 2*b), c)); x # optional - sage.combinat B[word: a] # B[word: c] + 2*B[word: b] # B[word: c] - sage: y = tensor( (c, a) ) + 1; y + sage: y = tensor((c, a)) + 1; y # optional - sage.combinat B[word: ] # B[word: ] + B[word: c] # B[word: a] - sage: x*y - 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] + sage: x * y # optional - sage.combinat + 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] TODO: optimize this implementation! diff --git a/src/sage/categories/bialgebras.py b/src/sage/categories/bialgebras.py index 441d924c964..fa6a7a1a507 100644 --- a/src/sage/categories/bialgebras.py +++ b/src/sage/categories/bialgebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Bialgebras """ diff --git a/src/sage/categories/bialgebras_with_basis.py b/src/sage/categories/bialgebras_with_basis.py index 831bab3f068..067d0b35b8e 100644 --- a/src/sage/categories/bialgebras_with_basis.py +++ b/src/sage/categories/bialgebras_with_basis.py @@ -92,32 +92,33 @@ def convolution_product(self, *maps): with the projection ``Proj2`` on the Hopf algebra of non-commutative symmetric functions:: - sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() - sage: T = R.convolution_product([Id, Id]) - sage: [T(R(comp)) for comp in Compositions(3)] + 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 [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) - sage: [T(R([i])) for i in range(1, 5)] + sage: T = R.convolution_product(Proj2, Id) # optional - sage.combinat + sage: [T(R([i])) for i in range(1, 5)] # optional - sage.combinat [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() - sage: T = m.convolution_product() - sage: [T(m(lam)) for lam in SetPartitions(0).list() + SetPartitions(2).list()] + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: T = m.convolution_product() # optional - sage.combinat + sage: [T(m(lam)) # optional - sage.combinat + ....: for lam in SetPartitions(0).list() + SetPartitions(2).list()] [m{}, 0, 0] Compute the convolution product of the projection ``Proj2`` with the identity on the Hopf algebra of symmetric functions in non-commuting variables:: - sage: T = m.convolution_product(Proj2, Id) - sage: [T(m(lam)) for lam in SetPartitions(3)] + sage: T = m.convolution_product(Proj2, Id) # optional - sage.combinat + sage: [T(m(lam)) for lam in SetPartitions(3)] # optional - sage.combinat [0, m{{1, 2}, {3}} + m{{1, 2, 3}}, m{{1, 2}, {3}} + m{{1, 2, 3}}, @@ -127,12 +128,15 @@ 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) - 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 + 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 + ....: [(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) - sage: T(x) + sage: T = QG.convolution_product(Antipode, Antipode, Id) # optional - sage.groups sage.combinat + sage: T(x) # optional - sage.groups sage.combinat 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) @@ -168,31 +172,32 @@ def adams_operator(self, n): EXAMPLES:: - sage: h = SymmetricFunctions(QQ).h() - sage: h[5].adams_operator(2) + sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat + sage: h[5].adams_operator(2) # optional - sage.combinat 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h[5].plethysm(2*h[1]) + sage: h[5].plethysm(2*h[1]) # optional - sage.combinat 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h([]).adams_operator(0) + sage: h([]).adams_operator(0) # optional - sage.combinat h[] - sage: h([]).adams_operator(1) + sage: h([]).adams_operator(1) # optional - sage.combinat h[] - sage: h[3,2].adams_operator(0) + sage: h[3,2].adams_operator(0) # optional - sage.combinat 0 - sage: h[3,2].adams_operator(1) + sage: h[3,2].adams_operator(1) # optional - sage.combinat h[3, 2] :: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S[4].adams_operator(5) - 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: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: S[4].adams_operator(5) # optional - sage.combinat + 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() - sage: m[[1,3],[2]].adams_operator(-2) + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: m[[1,3],[2]].adams_operator(-2) # optional - sage.combinat 3*m{{1}, {2, 3}} + 3*m{{1, 2}, {3}} + 6*m{{1, 2, 3}} - 2*m{{1, 3}, {2}} """ if n < 0: @@ -254,18 +259,18 @@ def convolution_product(self, *maps): sage: Id = lambda x: x sage: Antipode = lambda x: x.antipode() - sage: s = SymmetricFunctions(QQ).schur() - sage: s[3].convolution_product(Id, Id) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s[3].convolution_product(Id, Id) # optional - sage.combinat 2*s[2, 1] + 4*s[3] - sage: s[3,2].convolution_product(Id) == s[3,2] + sage: s[3,2].convolution_product(Id) == s[3,2] # optional - sage.combinat True The method accepts multiple arguments, or a single argument consisting of a list of maps:: - sage: s[3,2].convolution_product(Id, Id) + sage: s[3,2].convolution_product(Id, Id) # optional - sage.combinat 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]) + sage: s[3,2].convolution_product([Id, Id]) # optional - sage.combinat 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, @@ -273,28 +278,31 @@ def convolution_product(self, *maps): convolution algebra whose identity element is the composition of the counit and unit:: - sage: s[3,2].convolution_product() == s[3,2].convolution_product(Antipode, Id) == s[3,2].convolution_product(Id, Antipode) + sage: (s[3,2].convolution_product() # optional - sage.combinat + ....: == s[3,2].convolution_product(Antipode, Id) + ....: == s[3,2].convolution_product(Id, Antipode)) True :: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() - sage: Psi[2,1].convolution_product(Id, Id, Id) + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat + sage: Psi[2,1].convolution_product(Id, Id, Id) # optional - sage.combinat 3*Psi[1, 2] + 6*Psi[2, 1] - sage: (Psi[5,1] - Psi[1,5]).convolution_product(Id, Id, Id) + sage: (Psi[5,1] - Psi[1,5]).convolution_product(Id, Id, Id) # optional - sage.combinat -3*Psi[1, 5] + 3*Psi[5, 1] :: - sage: G = SymmetricGroup(3) - sage: QG = GroupAlgebra(G,QQ) - sage: x = QG.sum_of_terms([(p,p.length()) for p in Permutations(3)]); x + 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 + ....: 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) + sage: x.convolution_product(Id, Id) # optional - sage.combinat 5*[1, 2, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] - sage: x.convolution_product(Id, Id, Id) + sage: x.convolution_product(Id, Id, Id) # optional - sage.combinat 4*[1, 2, 3] + [1, 3, 2] + [2, 1, 3] + 3*[3, 2, 1] - sage: x.convolution_product([Id]*6) + sage: x.convolution_product([Id] * 6) # optional - sage.combinat 9*[1, 2, 3] TESTS:: @@ -304,57 +312,60 @@ def convolution_product(self, *maps): :: - sage: h = SymmetricFunctions(QQ).h() - sage: h[5].convolution_product([Id, Id]) + sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat + sage: h[5].convolution_product([Id, Id]) # optional - sage.combinat 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h.one().convolution_product([Id, Antipode]) + sage: h.one().convolution_product([Id, Antipode]) # optional - sage.combinat h[] - sage: h[3,2].convolution_product([Id, Antipode]) + sage: h[3,2].convolution_product([Id, Antipode]) # optional - sage.combinat 0 - sage: h.one().convolution_product([Id, Antipode]) == h.one().convolution_product() + sage: (h.one().convolution_product([Id, Antipode]) # optional - sage.combinat + ....: == h.one().convolution_product()) True :: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S[4].convolution_product([Id]*5) + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: S[4].convolution_product([Id] * 5) # optional - sage.combinat 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() - sage: m[[1,3],[2]].convolution_product([Antipode, Antipode]) + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: m[[1,3],[2]].convolution_product([Antipode, Antipode]) # optional - sage.combinat 3*m{{1}, {2, 3}} + 3*m{{1, 2}, {3}} + 6*m{{1, 2, 3}} - 2*m{{1, 3}, {2}} - sage: m[[]].convolution_product([]) + sage: m[[]].convolution_product([]) # optional - sage.combinat m{} - sage: m[[1,3],[2]].convolution_product([]) + sage: m[[1,3],[2]].convolution_product([]) # optional - sage.combinat 0 :: - sage: QS = SymmetricGroupAlgebra(QQ, 5) - sage: x = QS.sum_of_terms(zip(Permutations(5)[3:6],[1,2,3])); x + 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 [1, 2, 4, 5, 3] + 2*[1, 2, 5, 3, 4] + 3*[1, 2, 5, 4, 3] - sage: x.convolution_product([Antipode, Id]) + sage: x.convolution_product([Antipode, Id]) # optional - sage.combinat 6*[1, 2, 3, 4, 5] - sage: x.convolution_product(Id, Antipode, Antipode, Antipode) + sage: x.convolution_product(Id, Antipode, Antipode, Antipode) # optional - sage.combinat 3*[1, 2, 3, 4, 5] + [1, 2, 4, 5, 3] + 2*[1, 2, 5, 3, 4] :: - sage: G = SymmetricGroup(3) - sage: QG = GroupAlgebra(G,QQ) - sage: x = QG.sum_of_terms([(p,p.length()) for p in Permutations(3)]); x + 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 + ....: 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) + sage: x.convolution_product(Antipode, Id) # optional - sage.combinat 9*[1, 2, 3] - sage: x.convolution_product([Id, Antipode, Antipode, Antipode]) + sage: x.convolution_product([Id, Antipode, Antipode, Antipode]) # optional - sage.combinat 5*[1, 2, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] :: - sage: s[3,2].counit().parent() == s[3,2].convolution_product().parent() + sage: (s[3,2].counit().parent() # optional - sage.combinat + ....: == s[3,2].convolution_product().parent()) False """ # Be flexible on how the maps are entered: accept a list/tuple of diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index fe5e22cffd9..83e88ef748a 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -22,48 +22,49 @@ sage: Sets() Category of sets - sage: GSets(AbelianGroup([2,4,9])) + sage: GSets(AbelianGroup([2, 4, 9])) # optional - 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)) + sage: VectorSpaces(FiniteField(11)) # optional - sage.rings.finite_rings Category of vector spaces over Finite Field of size 11 sage: Ideals(IntegerRing()) Category of ring ideals in Integer Ring Let's request the category of some objects:: - sage: V = VectorSpace(RationalField(), 3) - sage: V.category() + sage: V = VectorSpace(RationalField(), 3) # optional - sage.modules + sage: V.category() # optional - sage.modules Category of finite dimensional vector spaces with basis over (number fields and quotient fields and metric spaces) - sage: G = SymmetricGroup(9) - sage: G.category() - Join of Category of finite enumerated permutation groups and - Category of finite weyl groups and - Category of well generated finite irreducible complex reflection groups + sage: G = SymmetricGroup(9) # optional - sage.groups + sage: G.category() # optional - 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) - sage: P.category() + sage: P = PerfectMatchings(3) # optional - sage.combinat sage.graphs + sage: P.category() # optional - sage.combinat sage.graphs Category of finite enumerated sets Let's check some memberships:: - sage: V in VectorSpaces(QQ) + sage: V in VectorSpaces(QQ) # optional - sage.modules True - sage: V in VectorSpaces(FiniteField(11)) + sage: V in VectorSpaces(FiniteField(11)) # optional - sage.modules sage.rings.finite_rings False - sage: G in Monoids() + sage: G in Monoids() # optional - sage.groups True - sage: P in Rings() + sage: P in Rings() # optional - sage.combinat sage.graphs False For parametrized categories one can use the following shorthand:: - sage: V in VectorSpaces + sage: V in VectorSpaces # optional - sage.modules True - sage: G in VectorSpaces + sage: G in VectorSpaces # optional - sage.groups False A parent ``P`` is in a category ``C`` if ``P.category()`` is a subcategory of @@ -83,11 +84,11 @@ True By default, the category of an element `x` of a parent `P` is the category - of all objects of `P` (this is dubious an may be deprecated):: + of all objects of `P` (this is dubious and may be deprecated):: - sage: V = VectorSpace(RationalField(), 3) - sage: v = V.gen(1) - sage: v.category() + sage: V = VectorSpace(RationalField(), 3) # optional - sage.modules + sage: v = V.gen(1) # optional - sage.modules + sage: v.category() # optional - sage.modules Category of elements of Vector space of dimension 3 over Rational Field """ @@ -308,7 +309,8 @@ class inheritance from ``C.parent_class``. sage: Ds().parent_class.__bases__ (, ) sage: Ds().parent_class.mro() - [, , , , <... 'object'>] + [, , + , , <... 'object'>] Note that two categories in the same class need not have the same ``super_categories``. For example, ``Algebras(QQ)`` has @@ -325,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 + sage: Algebras(GF(5)).parent_class is Algebras(GF(7)).parent_class # optional - sage.rings.finite_rings True sage: F = FractionField(ZZ['t']) sage: Coalgebras(F).parent_class is Coalgebras(FractionField(F['x'])).parent_class @@ -565,9 +567,11 @@ def an_instance(cls): sage: Algebras.an_instance() Category of algebras over Rational Field sage: Bimodules.an_instance() - Category of bimodules over Rational Field on the left and Real Field with 53 bits of precision on the right + Category of bimodules over Rational Field on the left + and Real Field with 53 bits of precision on the right sage: AlgebraIdeals.an_instance() - Category of algebra ideals in Univariate Polynomial Ring in x over Rational Field + Category of algebra ideals + in Univariate Polynomial Ring in x over Rational Field """ return cls() @@ -724,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) - sage: F in VectorSpaces + sage: F = FreeModule(QQ, 3) # optional - sage.modules + sage: F in VectorSpaces # optional - sage.modules True - sage: F = FreeModule(ZZ,3) - sage: F in VectorSpaces + sage: F = FreeModule(ZZ, 3) # optional - sage.modules + sage: F in VectorSpaces # optional - sage.modules False - sage: F in Algebras + sage: F in Algebras # optional - sage.modules False TESTS: @@ -798,14 +802,14 @@ def category_graph(self): EXAMPLES:: sage: C = Algebras(QQ) - sage: G = C.category_graph() - sage: G.is_directed_acyclic() + sage: G = C.category_graph() # optional - sage.graphs + sage: G.is_directed_acyclic() # optional - 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() + sage: Graph(G).girth() # optional - sage.graphs 4 """ return category_graph([self]) @@ -928,8 +932,8 @@ def _set_of_super_categories(self): TESTS:: - sage: C = HopfAlgebrasWithBasis(GF(7)) - sage: C._set_of_super_categories == frozenset(C._all_super_categories_proper) + 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 True """ return frozenset(self._all_super_categories_proper) @@ -1669,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 + sage: Algebras(GF(7)).parent_class is Algebras(GF(5)).parent_class # optional - sage.rings.finite_rings True sage: Algebras(QQ).parent_class is Algebras(ZZ).parent_class False @@ -1714,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 + sage: Algebras(GF(5)).element_class is Algebras(GF(3)).element_class # optional - sage.rings.finite_rings True sage: Algebras(QQ).element_class is Algebras(ZZ).element_class False @@ -1788,9 +1792,9 @@ def is_subcategory(self, c): :: - sage: M3 = VectorSpaces(FiniteField(3)) - sage: M9 = VectorSpaces(FiniteField(9, 'a')) - sage: M3.is_subcategory(M9) + 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 False Join categories are properly handled:: @@ -1801,16 +1805,16 @@ def is_subcategory(self, c): :: - sage: V3 = VectorSpaces(FiniteField(3)) + sage: V3 = VectorSpaces(FiniteField(3)) # optional - sage.rings.finite_rings sage: POSet = PartiallyOrderedSets() - sage: PoV3 = Category.join((V3, POSet)) - sage: A3 = AlgebrasWithBasis(FiniteField(3)) - sage: PoA3 = Category.join((A3, POSet)) - sage: PoA3.is_subcategory(PoV3) + 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 True - sage: PoV3.is_subcategory(PoV3) + sage: PoV3.is_subcategory(PoV3) # optional - sage.rings.finite_rings True - sage: PoV3.is_subcategory(PoA3) + sage: PoV3.is_subcategory(PoA3) # optional - sage.rings.finite_rings False """ if c is self: @@ -1852,7 +1856,8 @@ def or_subcategory(self, category=None, join=False): sage: Monoids().or_subcategory(EnumeratedSets()) Traceback (most recent call last): ... - ValueError: Subcategory of `Category of monoids` required; got `Category of enumerated sets` + ValueError: Subcategory of `Category of monoids` required; + got `Category of enumerated sets` Otherwise, the two categories are joined together:: @@ -2077,7 +2082,8 @@ def _with_axiom(self, axiom): sage: Magmas().Finite().Commutative().super_categories() [Category of commutative magmas, Category of finite sets] - sage: Algebras(QQ).WithBasis().Commutative() is Algebras(QQ).Commutative().WithBasis() + sage: C = Algebras(QQ).WithBasis().Commutative() + sage: C is Algebras(QQ).Commutative().WithBasis() True When ``axiom`` is not defined for ``self``, ``self`` is returned:: @@ -2252,7 +2258,9 @@ def _sort(categories): Category of commutative magmas, Category of finite sets, Category of facade sets) - sage: Category._sort(Category._flatten_categories([Sets().Finite(), Algebras(QQ).WithBasis(), Semigroups().Finite(), Sets().Facade(),Algebras(QQ).Commutative(), Algebras(QQ).Graded().WithBasis()], sage.categories.category.JoinCategory)) + sage: Category._sort(Category._flatten_categories([Sets().Finite(), Algebras(QQ).WithBasis(), Semigroups().Finite(), + ....: Sets().Facade(), Algebras(QQ).Commutative(), Algebras(QQ).Graded().WithBasis()], + ....: sage.categories.category.JoinCategory)) (Category of algebras with basis over Rational Field, Category of algebras with basis over Rational Field, Category of graded algebras over Rational Field, @@ -2597,7 +2605,7 @@ def category_sample(): EXAMPLES:: sage: from sage.categories.category import category_sample - sage: sorted(category_sample(), key=str) + sage: sorted(category_sample(), key=str) # optional - 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, @@ -2636,14 +2644,14 @@ def category_graph(categories=None): EXAMPLES:: - sage: G = sage.categories.category.category_graph(categories = [Groups()]) - sage: G.vertices(sort=True) + sage: G = sage.categories.category.category_graph(categories=[Groups()]) # optional - sage.graphs + sage: G.vertices(sort=True) # optional - sage.graphs ['groups', 'inverse unital magmas', 'magmas', 'monoids', 'objects', 'semigroups', 'sets', 'sets with partial maps', 'unital magmas'] - sage: G.plot() + sage: G.plot() # optional - sage.graphs sage.plot Graphics object consisting of 20 graphics primitives - sage: sage.categories.category.category_graph().plot() + sage: sage.categories.category.category_graph().plot() # optional - sage.graphs sage.plot Graphics object consisting of ... graphics primitives """ from sage import graphs @@ -2691,15 +2699,15 @@ class CategoryWithParameters(Category): EXAMPLES:: - sage: C1 = Algebras(GF(5)) - sage: C2 = Algebras(GF(3)) + sage: C1 = Algebras(GF(5)) # optional - sage.rings.finite_rings + sage: C2 = Algebras(GF(3)) # optional - sage.rings.finite_rings sage: C3 = Algebras(ZZ) sage: from sage.categories.category import CategoryWithParameters - sage: isinstance(C1, CategoryWithParameters) + sage: isinstance(C1, CategoryWithParameters) # optional - sage.rings.finite_rings True - sage: C1.parent_class is C2.parent_class + sage: C1.parent_class is C2.parent_class # optional - sage.rings.finite_rings True - sage: C1.parent_class is C3.parent_class + sage: C1.parent_class is C3.parent_class # optional - sage.rings.finite_rings False .. automethod:: Category._make_named_class @@ -2744,7 +2752,7 @@ def _make_named_class(self, name, method_provider, cache=False, **options): The categories of bimodules over the fields ``CC`` or ``RR`` provide the same methods to their parents and elements:: - sage: Bimodules(ZZ,RR).parent_class is Bimodules(ZZ,RDF).parent_class #indirect doctest + 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 True @@ -2918,12 +2926,12 @@ class JoinCategory(CategoryWithParameters): the underlying implementation is the same for all finite fields, we have:: - sage: G = SymmetricGroup(10) - sage: A3 = G.algebra(GF(3)) - sage: A5 = G.algebra(GF(5)) - sage: type(A3.category()) + 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: type(A3) is type(A5) + sage: type(A3) is type(A5) # optional - sage.groups sage.rings.finite_rings True .. automethod:: Category._repr_object_names diff --git a/src/sage/categories/category_types.py b/src/sage/categories/category_types.py index 4469a57a996..ef0fb9472bb 100644 --- a/src/sage/categories/category_types.py +++ b/src/sage/categories/category_types.py @@ -72,14 +72,14 @@ def _call_(self, x): """ EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: x = V.0 - sage: C = x.category() - sage: C + 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 Category of elements of Vector space of dimension 3 over Rational Field - sage: w = C([1,2,3]); w # indirect doctest + sage: w = C([1, 2, 3]); w # indirect doctest # optional - sage.modules (1, 2, 3) - sage: w.category() + sage: w.category() # optional - sage.modules Category of elements of Vector space of dimension 3 over Rational Field """ return self.__object(x) @@ -129,9 +129,9 @@ def _latex_(self): r""" EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: x = V.0 - sage: latex(x.category()) # indirect doctest + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: x = V.0 # optional - sage.modules + sage: latex(x.category()) # indirect doctest # optional - sage.modules \mathbf{Elt}_{\Bold{Q}^{3}} """ return "\\mathbf{Elt}_{%s}"%latex(self.__object) @@ -153,11 +153,11 @@ class Category_over_base(CategoryWithParameters): EXAMPLES:: - sage: Algebras(GF(2)).element_class is Algebras(GF(3)).element_class + sage: Algebras(GF(2)).element_class is Algebras(GF(3)).element_class # optional - sage.rings.finite_rings True - sage: C = GF(2).category() - sage: Algebras(GF(2)).parent_class is Algebras(C).parent_class + 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 True sage: C = ZZ.category() @@ -278,7 +278,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() + sage: Algebras(GF(2).category())._repr_object_names() # optional - sage.rings.finite_rings 'algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups)' """ base = self.__base @@ -338,9 +338,9 @@ def __init__(self, base, name=None): EXAMPLES:: - sage: C = Algebras(GF(2)); C + sage: C = Algebras(GF(2)); C # optional - sage.rings.finite_rings Category of algebras over Finite Field of size 2 - sage: TestSuite(C).run() + sage: TestSuite(C).run() # optional - sage.rings.finite_rings """ from sage.categories.rings import Rings if not (base in Rings() or @@ -355,8 +355,8 @@ def base_ring(self): EXAMPLES:: - sage: C = Algebras(GF(2)) - sage: C.base_ring() + sage: C = Algebras(GF(2)) # optional - sage.rings.finite_rings + sage: C.base_ring() # optional - sage.rings.finite_rings Finite Field of size 2 """ return self.base() @@ -399,11 +399,11 @@ def _subcategory_hook_(self, C): sage: VectorSpaces(QQ)._subcategory_hook_(VectorSpaces(QQ) & Rings()) Unknown - sage: Sym = SymmetricFunctions(QQ) - sage: from sage.combinat.sf.sfa import SymmetricFunctionsBases - sage: Modules(QQ)._subcategory_hook_(SymmetricFunctionsBases(Sym)) + 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 Unknown - sage: SymmetricFunctionsBases(Sym).is_subcategory(Modules(QQ)) + sage: SymmetricFunctionsBases(Sym).is_subcategory(Modules(QQ)) # optional - sage.combinat True Case 1: the two bases are categories; then the base of ``C`` @@ -411,7 +411,7 @@ def _subcategory_hook_(self, C): sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(Fields())) True - sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(Fields().Finite())) # todo: not implemented + sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(Fields().Finite())) # todo: not implemented True sage: VectorSpaces(Fields().Finite())._subcategory_hook_(Algebras(Fields())) False @@ -419,7 +419,7 @@ def _subcategory_hook_(self, C): Case 2: the base of ``self`` is a category; then the base of ``C`` shall be a parent in this category:: - sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(QQ)) # todo: not implemented + sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(QQ)) # todo: not implemented True sage: VectorSpaces(Fields().Finite())._subcategory_hook_(Algebras(QQ)) False @@ -430,15 +430,17 @@ def _subcategory_hook_(self, C): True sage: VectorSpaces(CC)._subcategory_hook_(Algebras(QQ)) # base ring in different categories False - sage: VectorSpaces(GF(2))._subcategory_hook_(Algebras(GF(3))) # base ring in the same category + sage: VectorSpaces(GF(2))._subcategory_hook_(Algebras(GF(3))) # base ring in the same category # optional - sage.rings.finite_rings 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, VectorSpaces(CC).parent_class) + sage: issubclass(Algebras(QQ).parent_class, # optional - sage.modules + ....: VectorSpaces(CC).parent_class) False - sage: issubclass(Algebras(GF(2)).parent_class, VectorSpaces(GF(3)).parent_class) + sage: issubclass(Algebras(GF(2)).parent_class, # optional - sage.modules sage.rings.finite_rings + ....: VectorSpaces(GF(3)).parent_class) True Check that :trac:`16618` is fixed: this `_subcategory_hook_` diff --git a/src/sage/categories/category_with_axiom.py b/src/sage/categories/category_with_axiom.py index 1c92e587456..a304ff996cd 100644 --- a/src/sage/categories/category_with_axiom.py +++ b/src/sage/categories/category_with_axiom.py @@ -182,7 +182,8 @@ class ``Semigroups.Infinite`` inheriting from :class:`CategoryWithAxiom`. :trac:`15648`), one should pass the option ``as_name`` to :class:`~sage.misc.lazy_import.LazyImport`:: - Finite = LazyImport('sage.categories.finite_groups', 'FiniteGroups', as_name='Finite') + Finite = LazyImport('sage.categories.finite_groups', 'FiniteGroups', + as_name='Finite') in order to prevent ``Groups.Finite`` to keep on reimporting ``FiniteGroups``. @@ -1730,7 +1731,8 @@ def base_category_class_and_axiom(cls): (, 'Finite') sage: base_category_class_and_axiom(FiniteDimensionalHopfAlgebrasWithBasis) - (, 'FiniteDimensional') + (, + 'FiniteDimensional') sage: base_category_class_and_axiom(HopfAlgebrasWithBasis) (, 'WithBasis') @@ -1742,7 +1744,9 @@ def base_category_class_and_axiom(cls): sage: base_category_class_and_axiom(FacadeSemigroups) Traceback (most recent call last): ... - AssertionError: Missing (lazy import) link for to for axiom Facade? + AssertionError: Missing (lazy import) link + for + to for axiom Facade? sage: Semigroups.Facade = FacadeSemigroups sage: base_category_class_and_axiom(FacadeSemigroups) @@ -1760,7 +1764,8 @@ def base_category_class_and_axiom(cls): sage: base_category_class_and_axiom(Sets.Infinite) Traceback (most recent call last): ... - TypeError: Could not retrieve the base category class and axiom for . + TypeError: Could not retrieve the base category class and axiom + for . ... """ if "." in cls.__name__: @@ -1812,7 +1817,8 @@ def axiom_of_nested_class(cls, nested_cls): sage: from sage.categories.category_with_axiom import TestObjects, axiom_of_nested_class sage: axiom_of_nested_class(TestObjects, TestObjects.FiniteDimensional) 'FiniteDimensional' - sage: axiom_of_nested_class(TestObjects.FiniteDimensional, TestObjects.FiniteDimensional.Finite) + sage: axiom_of_nested_class(TestObjects.FiniteDimensional, + ....: TestObjects.FiniteDimensional.Finite) 'Finite' sage: axiom_of_nested_class(Sets, FiniteSets) 'Finite' @@ -2456,9 +2462,9 @@ def axioms(self): sage: C.axioms() frozenset({'Finite'}) - sage: C = Modules(GF(5)).FiniteDimensional(); C + sage: C = Modules(GF(5)).FiniteDimensional(); C # optional - sage.rings.finite_rings Category of finite dimensional vector spaces over Finite Field of size 5 - sage: sorted(C.axioms()) + sage: sorted(C.axioms()) # optional - sage.rings.finite_rings ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Finite', 'FiniteDimensional'] @@ -2466,7 +2472,7 @@ def axioms(self): ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'FiniteDimensional', 'Unital', 'WithBasis'] - sage: sorted(FiniteMonoids().Algebras(GF(3)).axioms()) + sage: sorted(FiniteMonoids().Algebras(GF(3)).axioms()) # optional - sage.rings.finite_rings ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'Finite', 'FiniteDimensional', 'Unital', 'WithBasis'] @@ -2543,7 +2549,8 @@ class CategoryWithAxiom_singleton(Category_singleton, CategoryWithAxiom):#, Cate sage: isinstance(C, Category_over_base_ring) # todo: not implemented True sage: C.FiniteDimensional() - Category of finite dimensional connected test objects over base ring over Ring of integers modulo 2 + Category of finite dimensional connected test objects + over base ring over Ring of integers modulo 2 sage: C.Connected() Category of connected test objects over base ring over Ring of integers modulo 2 """ @@ -2790,7 +2797,8 @@ def super_categories(self): Category of unital test objects over base ring over Rational Field sage: TestObjectsOverBaseRing.FiniteDimensional.Unital.an_instance() Category of finite dimensional unital test objects over base ring over Rational Field - sage: TestSuite(TestObjectsOverBaseRing(QQ).FiniteDimensional().Unital().Commutative()).run() + sage: C = TestObjectsOverBaseRing(QQ).FiniteDimensional().Unital().Commutative() + sage: TestSuite(C).run() """ return [TestObjects()] diff --git a/src/sage/categories/chain_complexes.py b/src/sage/categories/chain_complexes.py index b1d8c578e60..8ce3e6145bc 100644 --- a/src/sage/categories/chain_complexes.py +++ b/src/sage/categories/chain_complexes.py @@ -67,27 +67,27 @@ def homology(self, n=None): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: C.homology(0) + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules + sage: C.homology(0) # optional - sage.modules Z x Z - sage: C.homology(1) + sage: C.homology(1) # optional - sage.modules Z x C3 - sage: C.homology(2) + sage: C.homology(2) # optional - sage.modules 0 :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) - sage: C = A.cdg_algebra({z: x*y}) - sage: C.homology(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 Free module generated by {[1]} over Rational Field - sage: C.homology(1) + sage: C.homology(1) # optional - sage.combinat sage.modules Free module generated by {} over Rational Field - sage: C.homology(2) + sage: C.homology(2) # optional - sage.combinat sage.modules Free module generated by {[x], [y]} over Rational Field - sage: C.homology(3) + sage: C.homology(3) # optional - sage.combinat sage.modules Free module generated by {} over Rational Field - sage: C.homology(4) + sage: C.homology(4) # optional - sage.combinat sage.modules Free module generated by {[x^2], [y^2]} over Rational Field """ @@ -99,17 +99,18 @@ def differential(self, *args, **kwargs): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: C.differential(0) + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules + sage: C.differential(0) # optional - sage.modules [3 0 0] [0 0 0] :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) - sage: C = A.cdg_algebra({z: x*y}) - sage: C.differential() - Differential of Commutative Differential Graded Algebra with generators ('x', 'y', 'z') in degrees (2, 2, 3) over Rational Field + 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 + Differential of Commutative Differential Graded Algebra with + generators ('x', 'y', 'z') in degrees (2, 2, 3) over Rational Field Defn: x --> 0 y --> 0 z --> x*y @@ -123,10 +124,10 @@ 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: 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 Mixed differential form one on the Euclidean space E^3 """ @@ -143,10 +144,10 @@ 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: 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 [one] """ try: @@ -168,35 +169,35 @@ class HomologyFunctor(Functor): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) - sage: H(C) + 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 Z x C3 :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) - sage: C = A.cdg_algebra({z: x*y}) - sage: H = HomologyFunctor(ChainComplexes(QQ), 2) - sage: H(C) + 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 Free module generated by {[x], [y]} over Rational Field Applying to a chain map:: - sage: S = simplicial_complexes.Sphere(1); S + sage: S = simplicial_complexes.Sphere(1); S # optional - sage.graphs Minimal triangulation of the 1-sphere - sage: C = S.chain_complex() - sage: C.differential() + 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)} - sage: G = Hom(C,C) - sage: x = G(f) - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) - sage: H(C) + 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 Z - sage: H(x) + sage: H(x) # optional - sage.graphs sage.modules Generic morphism: From: Z To: Z @@ -225,9 +226,9 @@ def _apply_functor(self, x): TESTS:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) - sage: H._apply_functor(C) + 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 Z x C3 """ @@ -239,15 +240,15 @@ 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: 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 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() # optional - sage.symbolic + sage: id_star(one) # optional - sage.symbolic [one] """ from .morphism import SetMorphism diff --git a/src/sage/categories/classical_crystals.py b/src/sage/categories/classical_crystals.py index 581b094f6d8..744b1cb6e44 100644 --- a/src/sage/categories/classical_crystals.py +++ b/src/sage/categories/classical_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs, sage.combinat r""" Classical Crystals """ diff --git a/src/sage/categories/coalgebras.py b/src/sage/categories/coalgebras.py index ecbf5d15baf..870315dc644 100644 --- a/src/sage/categories/coalgebras.py +++ b/src/sage/categories/coalgebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Coalgebras """ diff --git a/src/sage/categories/coalgebras_with_basis.py b/src/sage/categories/coalgebras_with_basis.py index 5518804d649..844f5e5a294 100644 --- a/src/sage/categories/coalgebras_with_basis.py +++ b/src/sage/categories/coalgebras_with_basis.py @@ -61,10 +61,12 @@ def coproduct_on_basis(self, i): EXAMPLES:: - 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._group.gens() - sage: A.coproduct_on_basis(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - 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 B[(1,2,3)] # B[(1,2,3)] """ @@ -79,12 +81,14 @@ def coproduct(self): EXAMPLES:: - 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() - sage: a, A.coproduct(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - 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.algebra_generators() # optional - sage.groups sage.modules + sage: a, A.coproduct(a) # optional - sage.groups sage.modules (B[(1,2,3)], B[(1,2,3)] # B[(1,2,3)]) - sage: b, A.coproduct(b) + sage: b, A.coproduct(b) # optional - sage.groups sage.modules (B[(1,3)], B[(1,3)] # B[(1,3)]) """ @@ -111,10 +115,12 @@ def counit_on_basis(self, i): EXAMPLES:: - 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._group.gens() - sage: A.counit_on_basis(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - 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 1 """ @@ -127,12 +133,14 @@ def counit(self): EXAMPLES:: - 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() - sage: a, A.counit(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - 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.algebra_generators() # optional - sage.groups sage.modules + sage: a, A.counit(a) # optional - sage.groups sage.modules (B[(1,2,3)], 1) - sage: b, A.counit(b) + sage: b, A.counit(b) # optional - sage.groups sage.modules (B[(1,3)], 1) """ @@ -152,29 +160,29 @@ def coproduct_iterated(self, n=1): EXAMPLES:: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() - sage: Psi[2,2].coproduct_iterated(0) + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat + sage: Psi[2,2].coproduct_iterated(0) # optional - sage.combinat Psi[2, 2] - sage: Psi[2,2].coproduct_iterated(2) + sage: Psi[2,2].coproduct_iterated(2) # optional - sage.combinat 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() - sage: p[5,2,2].coproduct_iterated() + sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat + sage: p[5,2,2].coproduct_iterated() # optional - sage.combinat 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) + sage: p([]).coproduct_iterated(3) # optional - sage.combinat p[] # p[] # p[] # p[] :: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() - sage: Psi[2,2].coproduct_iterated(0) + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat + sage: Psi[2,2].coproduct_iterated(0) # optional - sage.combinat Psi[2, 2] - sage: Psi[2,2].coproduct_iterated(3) + sage: Psi[2,2].coproduct_iterated(3) # optional - sage.combinat 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[] @@ -183,14 +191,14 @@ def coproduct_iterated(self, n=1): :: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() - sage: m[[1,3],[2]].coproduct_iterated(2) + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: m[[1,3],[2]].coproduct_iterated(2) # optional - sage.combinat 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) + sage: m[[]].coproduct_iterated(3), m[[1,3],[2]].coproduct_iterated(0) # optional - sage.combinat (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 c1383022833..9300f4d6db5 100644 --- a/src/sage/categories/commutative_additive_groups.py +++ b/src/sage/categories/commutative_additive_groups.py @@ -79,10 +79,11 @@ def additive_order(self): sage: G((0,1)).additive_order() +Infinity - sage: K = GF(9) - sage: H = cartesian_product([cartesian_product([Zmod(2),Zmod(9)]), K]) - sage: z = H(((1,2), K.gen())) - sage: z.additive_order() + sage: K = GF(9) # optional - sage.rings.finite_rings + sage: H = cartesian_product([ # optional - sage.rings.finite_rings + ....: 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 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 15824e09644..e0835848e91 100644 --- a/src/sage/categories/commutative_algebra_ideals.py +++ b/src/sage/categories/commutative_algebra_ideals.py @@ -24,14 +24,16 @@ class CommutativeAlgebraIdeals(Category_ideal): sage: C = CommutativeAlgebraIdeals(QQ['x']) sage: C - Category of commutative algebra ideals in Univariate Polynomial Ring in x over Rational Field + Category of commutative algebra ideals in + Univariate Polynomial Ring in x over Rational Field """ def __init__(self, A): """ EXAMPLES:: sage: CommutativeAlgebraIdeals(ZZ['x']) - Category of commutative algebra ideals in Univariate Polynomial Ring in x over Integer Ring + Category of commutative algebra ideals in + Univariate Polynomial Ring in x over Integer Ring sage: CommutativeAlgebraIdeals(ZZ) Traceback (most recent call last): @@ -43,7 +45,7 @@ def __init__(self, A): ... TypeError: A (=Ring of integers modulo 4) must be a commutative algebra - sage: CommutativeAlgebraIdeals(Partitions(4)) + sage: CommutativeAlgebraIdeals(Partitions(4)) # optional - sage.combinat sage.modules 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 cff24e1298a..bdff573db87 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)) - sage: M + sage: M = CommutativeAlgebras(GF(19)) # optional - sage.rings.finite_rings + sage: M # optional - sage.rings.finite_rings 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) + sage: FreeAlgebra(QQ, 2, 'a,b') in CommutativeAlgebras(QQ) # optional - sage.combinat False TODO: get rid of this method once all commutative algebras in @@ -80,12 +80,12 @@ def extra_super_categories(self): TESTS:: - sage: X = algebras.Shuffle(QQ, 'ab') - sage: Y = algebras.Shuffle(QQ, 'bc') - sage: X in Algebras(QQ).Commutative() + 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 True - sage: T = tensor([X, Y]) - sage: T in CommutativeRings() + sage: T = tensor([X, Y]) # optional - sage.combinat + sage: T in CommutativeRings() # optional - sage.combinat True """ return [CommutativeRings()] diff --git a/src/sage/categories/commutative_ring_ideals.py b/src/sage/categories/commutative_ring_ideals.py index 115b79afb80..837f1edf944 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)) + sage: CommutativeRingIdeals(Partitions(4)) # optional - 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 71e08a5070d..6219c1070bb 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() + sage: GroupAlgebra(DihedralGroup(3), QQ) in CommutativeRings() # optional - sage.groups sage.modules False - sage: MatrixSpace(QQ,2,2) in CommutativeRings() + sage: MatrixSpace(QQ, 2, 2) in CommutativeRings() # optional - sage.modules False GroupAlgebra should be fixed:: - sage: GroupAlgebra(CyclicPermutationGroup(3), QQ) in CommutativeRings() # todo: not implemented + sage: GroupAlgebra(CyclicPermutationGroup(3), QQ) in CommutativeRings() # todo: not implemented # optional - sage.groups sage.modules True """ @@ -110,92 +110,98 @@ 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) - sage: k = GF(5^4) - sage: z4 = k.gen() + 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) - sage: K - Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base + sage: K = k.over(F) # optional - sage.rings.finite_rings + sage: K # optional - sage.rings.finite_rings + 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() + sage: K.gen() # optional - sage.rings.finite_rings z4 - sage: K(z4) + sage: K(z4) # optional - 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') - sage: Ka - Field in a with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: Ka.gen() + sage: Ka = k.over(F, name='a') # optional - sage.rings.finite_rings + sage: Ka # optional - sage.rings.finite_rings + Field in a with defining polynomial + x^2 + (4*z2 + 3)*x + z2 over its base + sage: Ka.gen() # optional - sage.rings.finite_rings a - sage: Ka(z4) + sage: Ka(z4) # optional - sage.rings.finite_rings a - sage: Kb = k.over(F, gen=-z4+1, name='b') - sage: Kb + sage: Kb = k.over(F, gen=-z4+1, name='b') # optional - sage.rings.finite_rings + sage: Kb # optional - sage.rings.finite_rings Field in b with defining polynomial x^2 + z2*x + 4 over its base - sage: Kb.gen() + sage: Kb.gen() # optional - sage.rings.finite_rings b - sage: Kb(-z4+1) + sage: Kb(-z4+1) # optional - sage.rings.finite_rings b Note that the shortcut ``K.`` is also available:: - sage: KKa. = k.over(F) - sage: KKa is Ka + sage: KKa. = k.over(F) # optional - sage.rings.finite_rings + sage: KKa is Ka # optional - sage.rings.finite_rings True Building an extension on top of another extension is allowed:: - sage: L = GF(5^12).over(K) - sage: L - 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() - Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: L # optional - 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 + 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() - [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 x^2 + (4*z2 + 3)*x + z2 over its base, + sage: L.bases() # optional - 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 + x^2 + (4*z2 + 3)*x + z2 over its base, Finite Field in z2 of size 5^2] When ``base`` is omitted, the canonical base of the ring is used:: sage: S. = QQ[] - sage: E = S.over() - sage: E + sage: E = S.over() # optional - sage.modules + sage: E # optional - sage.modules Univariate Polynomial Ring in x over Rational Field over its base - sage: E.base_ring() + sage: E.base_ring() # optional - sage.modules Rational Field Here is an example where ``base`` is a defining morphism:: - 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 + 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 Field in b with defining polynomial x^2 - a over its base - sage: L.base_ring() + sage: L.base_ring() # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 - 2 Similarly, one can create a tower of extensions:: - sage: K = k.over() - sage: L = l.over(Hom(K,l)(f)) - sage: L + 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 Field in b with defining polynomial x^2 - a over its base - sage: L.base_ring() + sage: L.base_ring() # optional - sage.rings.number_field Field in a with defining polynomial x^2 - 2 over its base - sage: L.bases() + sage: L.bases() # optional - sage.rings.number_field [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] @@ -221,7 +227,8 @@ class Finite(CategoryWithAxiom): EXAMPLES:: - sage: cartesian_product([Zmod(34), GF(5)]) in Rings().Commutative().Finite() + sage: cartesian_product([Zmod(34), # optional - sage.rings.finite_rings + ....: GF(5)]) in Rings().Commutative().Finite() True """ class ParentMethods: @@ -278,34 +285,34 @@ def cyclotomic_cosets(self, q, cosets=None): cyclic, the set of squares is a particular case of cyclotomic coset:: - sage: K = GF(25,'z') - sage: a = K.multiplicative_generator() - sage: K.cyclotomic_cosets(a**2,cosets=[1]) + 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 [[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()) + sage: sorted(b for b in K if not b.is_zero() and b.is_square()) # optional - sage.rings.finite_rings [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') - sage: a = K.multiplicative_generator() - sage: R. = PolynomialRing(K, 'X') - sage: a.minimal_polynomial('X') + 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 X^3 + 2*X + 1 - sage: cyc3 = Zmod(26).cyclotomic_cosets(3,cosets=[1]); cyc3 + sage: cyc3 = Zmod(26).cyclotomic_cosets(3, cosets=[1]); cyc3 # optional - sage.rings.finite_rings [[1, 3, 9]] - sage: prod(X - a**i for i in cyc3[0]) + sage: prod(X - a**i for i in cyc3[0]) # optional - sage.rings.finite_rings X^3 + 2*X + 1 - sage: (a**7).minimal_polynomial('X') + sage: (a**7).minimal_polynomial('X') # optional - sage.rings.finite_rings X^3 + X^2 + 2*X + 1 - sage: cyc7 = Zmod(26).cyclotomic_cosets(3,cosets=[7]); cyc7 + sage: cyc7 = Zmod(26).cyclotomic_cosets(3, cosets=[7]); cyc7 # optional - sage.rings.finite_rings [[7, 11, 21]] - sage: prod(X - a**i for i in cyc7[0]) + sage: prod(X - a**i for i in cyc7[0]) # optional - sage.rings.finite_rings X^3 + X^2 + 2*X + 1 Cyclotomic cosets of fields are useful in combinatorial design @@ -314,26 +321,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) - sage: a = K.multiplicative_generator() - sage: H = K.cyclotomic_cosets(a**2, cosets=[1,2]); H + 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 [[1, 4], [2, 3]] - sage: sorted(x-y for D in H for x in D for y in D if x != y) + sage: sorted(x - y for D in H for x in D for y in D if x != y) # optional - sage.rings.finite_rings [1, 2, 3, 4] - sage: K = GF(37) - sage: a = K.multiplicative_generator() - sage: H = K.cyclotomic_cosets(a**4, cosets=[1]); H + 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 [[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) + sage: sorted(x - y for D in H for x in D for y in D if x != y) # optional - 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)]) - sage: a = R((3,5)) - sage: R.cyclotomic_cosets((3,5), [(1,1)]) + 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 [[(1, 1), (2, 11), (3, 5), (4, 9), (5, 3), (6, 13)]] """ q = self(q) @@ -373,7 +380,8 @@ def extra_super_categories(self): sage: CommutativeRings().Commutative().CartesianProducts().extra_super_categories() [Category of commutative rings] - sage: cartesian_product([ZZ, Zmod(34), QQ, GF(5)]) in CommutativeRings() + sage: cartesian_product([ZZ, Zmod(34), # optional - sage.rings.finite_rings + ....: QQ, GF(5)]) in CommutativeRings() True """ return [CommutativeRings()] diff --git a/src/sage/categories/complete_discrete_valuation.py b/src/sage/categories/complete_discrete_valuation.py index e7bc01ddd28..71c7ec57015 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() + sage: Zp(7) in CompleteDiscreteValuationRings() # optional - sage.rings.padics True sage: QQ in CompleteDiscreteValuationRings() False sage: QQ[['u']] in CompleteDiscreteValuationRings() True - sage: Qp(7) in CompleteDiscreteValuationRings() + sage: Qp(7) in CompleteDiscreteValuationRings() # optional - sage.rings.padics False sage: TestSuite(CompleteDiscreteValuationRings()).run() """ @@ -49,10 +49,10 @@ def valuation(self): EXAMPLES:: - sage: R = Zp(7) - sage: x = R(7); x + sage: R = Zp(7) # optional - sage.rings.padics + sage: x = R(7); x # optional - sage.rings.padics 7 + O(7^21) - sage: x.valuation() + sage: x.valuation() # optional - sage.rings.padics 1 """ @@ -63,32 +63,32 @@ def denominator(self): EXAMPLES:: - sage: K = Qp(7) - sage: x = K(1/21) - sage: x.denominator() + sage: K = Qp(7) # optional - sage.rings.padics + sage: x = K(1/21) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 7 + O(7^21) - sage: x = K(7) - sage: x.denominator() + sage: x = K(7) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) Note that the denominator lives in the ring of integers:: - sage: x.denominator().parent() + sage: x.denominator().parent() # optional - 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 + sage: x = K(0, 5); x # optional - sage.rings.padics O(7^5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 7^5 + O(7^25) """ return self.parent()(1) @@ -101,26 +101,26 @@ def numerator(self): EXAMPLES:: - sage: K = Qp(7, 5) - sage: x = K(1/21) - sage: x.numerator() + 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 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + O(7^5) - sage: x == x.numerator() / x.denominator() + sage: x == x.numerator() / x.denominator() # optional - sage.rings.padics True Note that the numerator lives in the ring of integers:: - sage: x.numerator().parent() + sage: x.numerator().parent() # optional - sage.rings.padics 7-adic Ring with capped relative precision 5 TESTS:: - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.numerator() + sage: x.numerator() # optional - sage.rings.padics O(7^0) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 7^5 + O(7^10) """ return self @@ -146,21 +146,22 @@ def lift_to_precision(self, absprec=None): EXAMPLES:: - sage: R = ZpCA(17) - sage: R(-1,2).lift_to_precision(10) + sage: R = ZpCA(17) # optional - sage.rings.padics + sage: R(-1, 2).lift_to_precision(10) # optional - sage.rings.padics 16 + 16*17 + O(17^10) - sage: R(1,15).lift_to_precision(10) + sage: R(1, 15).lift_to_precision(10) # optional - sage.rings.padics 1 + O(17^15) - sage: R(1,15).lift_to_precision(30) + sage: R(1, 15).lift_to_precision(30) # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: precision higher than allowed by the precision cap - sage: R(-1,2).lift_to_precision().precision_absolute() == R.precision_cap() + sage: (R(-1, 2).lift_to_precision().precision_absolute() # optional - sage.rings.padics + ....: == R.precision_cap()) True - sage: R = Zp(5); c = R(17,3); c.lift_to_precision(8) + sage: R = Zp(5); c = R(17, 3); c.lift_to_precision(8) # optional - sage.rings.padics 2 + 3*5 + O(5^8) - sage: c.lift_to_precision().precision_relative() == R.precision_cap() + sage: c.lift_to_precision().precision_relative() == R.precision_cap() # optional - sage.rings.padics True """ @@ -171,13 +172,13 @@ class CompleteDiscreteValuationFields(Category_singleton): EXAMPLES:: - sage: Zp(7) in CompleteDiscreteValuationFields() + sage: Zp(7) in CompleteDiscreteValuationFields() # optional - sage.rings.padics False sage: QQ in CompleteDiscreteValuationFields() False - sage: LaurentSeriesRing(QQ,'u') in CompleteDiscreteValuationFields() + sage: LaurentSeriesRing(QQ, 'u') in CompleteDiscreteValuationFields() True - sage: Qp(7) in CompleteDiscreteValuationFields() + sage: Qp(7) in CompleteDiscreteValuationFields() # optional - sage.rings.padics True sage: TestSuite(CompleteDiscreteValuationFields()).run() """ @@ -199,10 +200,10 @@ def valuation(self): EXAMPLES:: - sage: K = Qp(7) - sage: x = K(7); x + sage: K = Qp(7) # optional - sage.rings.padics + sage: x = K(7); x # optional - sage.rings.padics 7 + O(7^21) - sage: x.valuation() + sage: x.valuation() # optional - sage.rings.padics 1 """ @@ -213,32 +214,32 @@ def denominator(self): EXAMPLES:: - sage: K = Qp(7) - sage: x = K(1/21) - sage: x.denominator() + sage: K = Qp(7) # optional - sage.rings.padics + sage: x = K(1/21) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 7 + O(7^21) - sage: x = K(7) - sage: x.denominator() + sage: x = K(7) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) Note that the denominator lives in the ring of integers:: - sage: x.denominator().parent() + sage: x.denominator().parent() # optional - 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 + sage: x = K(0, 5); x # optional - sage.rings.padics O(7^5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 7^5 + O(7^25) """ val = self.valuation() @@ -256,26 +257,26 @@ def numerator(self): EXAMPLES:: - sage: K = Qp(7, 5) - sage: x = K(1/21) - sage: x.numerator() + 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 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + O(7^5) - sage: x == x.numerator() / x.denominator() + sage: x == x.numerator() / x.denominator() # optional - sage.rings.padics True Note that the numerator lives in the ring of integers:: - sage: x.numerator().parent() + sage: x.numerator().parent() # optional - sage.rings.padics 7-adic Ring with capped relative precision 5 TESTS:: - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.numerator() + sage: x.numerator() # optional - sage.rings.padics O(7^0) - sage: x.denominator() + sage: x.denominator() # optional - 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 5b23c448a96..e55b16eb6a0 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 + sage: W = ComplexReflectionGroups().example(); W # optional - sage.combinat sage.groups 5-colored permutations of size 3 ``W`` is in the category of complex reflection groups:: - sage: W in ComplexReflectionGroups() + sage: W in ComplexReflectionGroups() # optional - sage.combinat sage.groups True TESTS:: - sage: TestSuite(W).run() - sage: TestSuite(ComplexReflectionGroups()).run() + sage: TestSuite(W).run() # optional - sage.combinat sage.groups + sage: TestSuite(ComplexReflectionGroups()).run() # optional - sage.combinat sage.groups """ @cached_method @@ -115,7 +115,7 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().example() + sage: ComplexReflectionGroups().example() # optional - sage.combinat sage.groups 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 + sage: W = CoxeterGroups().example(); W # optional - sage.groups The symmetric group on {0, ..., 3} - sage: W.rank() + sage: W.rank() # optional - sage.groups 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 b75cbcb3e5d..3bbe54cefc0 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 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.groups r""" Common category for Generalized Coxeter Groups or Complex Reflection Groups """ diff --git a/src/sage/categories/covariant_functorial_construction.py b/src/sage/categories/covariant_functorial_construction.py index ad402bfe09d..90a1c42b1cc 100644 --- a/src/sage/categories/covariant_functorial_construction.py +++ b/src/sage/categories/covariant_functorial_construction.py @@ -134,9 +134,10 @@ def category_from_parents(self, parents): EXAMPLES:: - sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]) - sage: tensor.category_from_parents((E, E, E)) - Category of tensor products of finite dimensional vector spaces with basis over Rational Field + sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]) # optional - sage.modules + sage: tensor.category_from_parents((E, E, E)) # optional - sage.modules + Category of tensor products of + finite dimensional vector spaces with basis over Rational Field """ from sage.structure.parent import Parent assert all(isinstance(parent, Parent) for parent in parents) @@ -213,8 +214,8 @@ def __call__(self, args, **kwargs): EXAMPLES:: - sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]); E.rename("E") - sage: tensor((E, E, E)) + sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]); E.rename("E") # optional - sage.modules + sage: tensor((E, E, E)) # optional - sage.modules E # E # E """ args = tuple(args) # a bit brute force; let's see if this becomes a bottleneck later @@ -399,10 +400,12 @@ def category_of(cls, category, *args): EXAMPLES:: - sage: sage.categories.tensor.TensorProductsCategory.category_of(ModulesWithBasis(QQ)) + sage: C = sage.categories.tensor.TensorProductsCategory + sage: C.category_of(ModulesWithBasis(QQ)) Category of tensor products of vector spaces with basis over Rational Field - sage: sage.categories.algebra_functor.AlgebrasCategory.category_of(FiniteMonoids(), QQ) + sage: C = sage.categories.algebra_functor.AlgebrasCategory + sage: C.category_of(FiniteMonoids(), QQ) Join of Category of finite dimensional algebras with basis over Rational Field and Category of monoid algebras over Rational Field and Category of finite set algebras over Rational Field @@ -540,7 +543,8 @@ def default_super_categories(cls, category, *args): Bialgebras are both algebras and coalgebras:: sage: Bialgebras(QQ).super_categories() - [Category of algebras over Rational Field, Category of coalgebras over Rational Field] + [Category of algebras over Rational Field, + Category of coalgebras over Rational Field] Hence tensor products of bialgebras are tensor products of algebras and tensor products of coalgebras:: @@ -551,8 +555,10 @@ def default_super_categories(cls, category, *args): Here is how :meth:`default_super_categories` was called internally:: - sage: sage.categories.tensor.TensorProductsCategory.default_super_categories(Bialgebras(QQ)) - Join of Category of tensor products of algebras over Rational Field and Category of tensor products of coalgebras over Rational Field + sage: C = sage.categories.tensor.TensorProductsCategory + sage: C.default_super_categories(Bialgebras(QQ)) + Join of Category of tensor products of algebras over Rational Field + and Category of tensor products of coalgebras over Rational Field We now show a similar example, with the ``Algebra`` functor which takes a parameter `\QQ`:: @@ -570,7 +576,8 @@ def default_super_categories(cls, category, *args): Here is how :meth:`default_super_categories` was called internally:: - sage: sage.categories.algebra_functor.AlgebrasCategory.default_super_categories(FiniteMonoids(), QQ) + sage: C = sage.categories.algebra_functor.AlgebrasCategory + sage: C.default_super_categories(FiniteMonoids(), QQ) Join of Category of finite dimensional algebras with basis over Rational Field and Category of monoid algebras over Rational Field and Category of finite set algebras over Rational Field @@ -609,7 +616,8 @@ def is_construction_defined_by_base(self): sage: Bialgebras(QQ).Graded().is_construction_defined_by_base() Traceback (most recent call last): ... - AttributeError: 'JoinCategory_with_category' object has no attribute 'is_construction_defined_by_base' + AttributeError: 'JoinCategory_with_category' object has + no attribute 'is_construction_defined_by_base' """ base = self.base_category() f = self._functor_category diff --git a/src/sage/categories/coxeter_group_algebras.py b/src/sage/categories/coxeter_group_algebras.py index c8a3d935f05..623b1078e60 100644 --- a/src/sage/categories/coxeter_group_algebras.py +++ b/src/sage/categories/coxeter_group_algebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat, sage.groups r""" Coxeter Group Algebras """ diff --git a/src/sage/categories/coxeter_groups.py b/src/sage/categories/coxeter_groups.py index 98fe35a0ab3..95c31d20695 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() + sage: FiniteCoxeterGroups().example() # optional - sage.combinat sage.groups The 5-th dihedral group of order 10 - sage: FiniteWeylGroups().example() + sage: FiniteWeylGroups().example() # optional - sage.combinat sage.groups The symmetric group on {0, ..., 3} - sage: WeylGroup(["B", 3]) + sage: WeylGroup(["B", 3]) # optional - sage.combinat sage.groups Weyl Group of type ['B', 3] (as a matrix group acting on the ambient space) - sage: S4 = SymmetricGroup(4); S4 + sage: S4 = SymmetricGroup(4); S4 # optional - sage.groups Symmetric group of order 4! as a permutation group - sage: S4 in CoxeterGroups().Finite() + sage: S4 in CoxeterGroups().Finite() # optional - sage.groups True Those will eventually be also in this category:: - sage: DihedralGroup(5) + sage: DihedralGroup(5) # optional - 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() + sage: TestSuite(W).run() # optional - sage.combinat """ def super_categories(self): @@ -136,8 +136,8 @@ def coxeter_matrix(self): EXAMPLES:: - sage: G = WeylGroup(['A',3]) - sage: G.coxeter_matrix() + sage: G = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: G.coxeter_matrix() # optional - sage.combinat sage.groups [1 3 2] [3 1 3] [2 3 1] @@ -150,14 +150,14 @@ def index_set(self): EXAMPLES:: - sage: W = CoxeterGroup([[1,3],[3,1]]) - sage: W.index_set() + sage: W = CoxeterGroup([[1,3],[3,1]]) # optional - sage.combinat sage.groups + sage: W.index_set() # optional - sage.combinat sage.groups (1, 2) - sage: W = CoxeterGroup([[1,3],[3,1]], index_set=['x', 'y']) - sage: W.index_set() + 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 ('x', 'y') - sage: W = CoxeterGroup(['H',3]) - sage: W.index_set() + sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups + sage: W.index_set() # optional - sage.combinat sage.groups (1, 2, 3) """ return self.coxeter_matrix().index_set() @@ -168,18 +168,18 @@ def coxeter_diagram(self): EXAMPLES:: - sage: W = CoxeterGroup(['H',3], implementation="reflection") - sage: G = W.coxeter_diagram(); G + 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 Graph on 3 vertices - sage: G.edges(sort=True) + sage: G.edges(sort=True) # optional - sage.combinat sage.groups sage.graphs [(1, 2, 3), (2, 3, 5)] - sage: CoxeterGroup(G) is W + sage: CoxeterGroup(G) is W # optional - sage.combinat sage.groups sage.graphs True - sage: G = Graph([(0, 1, 3), (1, 2, oo)]) - sage: W = CoxeterGroup(G) - sage: W.coxeter_diagram() == G + 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 True - sage: CoxeterGroup(W.coxeter_diagram()) is W + sage: CoxeterGroup(W.coxeter_diagram()) is W # optional - sage.combinat sage.groups sage.graphs True """ return self.coxeter_matrix().coxeter_graph() @@ -190,8 +190,8 @@ def coxeter_type(self): EXAMPLES:: - sage: W = CoxeterGroup(['H',3]) - sage: W.coxeter_type() + sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups + sage: W.coxeter_type() # optional - sage.combinat sage.groups Coxeter type of ['H', 3] """ return self.coxeter_matrix().coxeter_type() @@ -203,12 +203,12 @@ def braid_relations(self): EXAMPLES:: - sage: W = WeylGroup(["A",2]) - sage: W.braid_relations() + sage: W = WeylGroup(["A", 2]) # optional - sage.combinat sage.groups + sage: W.braid_relations() # optional - sage.combinat sage.groups [[[1, 2, 1], [2, 1, 2]]] - sage: W = WeylGroup(["B",3]) - sage: W.braid_relations() + sage: W = WeylGroup(["B", 3]) # optional - sage.combinat sage.groups + sage: W.braid_relations() # optional - sage.combinat sage.groups [[[1, 2, 1], [2, 1, 2]], [[1, 3], [3, 1]], [[2, 3, 2, 3], [3, 2, 3, 2]]] """ rels = [] @@ -228,16 +228,16 @@ def braid_group_as_finitely_presented_group(self): EXAMPLES:: - sage: W = CoxeterGroup(['A',2]) - sage: W.braid_group_as_finitely_presented_group() + sage: W = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: W.braid_group_as_finitely_presented_group() # optional - sage.combinat sage.groups Finitely presented group < S1, S2 | S1*S2*S1*S2^-1*S1^-1*S2^-1 > - sage: W = WeylGroup(['B',2]) - sage: W.braid_group_as_finitely_presented_group() + sage: W = WeylGroup(['B', 2]) # optional - sage.combinat sage.groups + sage: W.braid_group_as_finitely_presented_group() # optional - 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 - sage: W.braid_group_as_finitely_presented_group() # optional - gap3 + sage: W.braid_group_as_finitely_presented_group() # optional - gap3 Finitely presented group < SAA, SBB, S5 | (SAA*SBB)^2*(SAA^-1*SBB^-1)^2, SAA*S5*SAA^-1*S5^-1, SBB*S5*SBB*S5^-1*SBB^-1*S5^-1 > @@ -279,10 +279,10 @@ def braid_orbit(self, word): sage: word = w.reduced_word(); word [0, 1, 2, 1] - sage: sorted(W.braid_orbit(word)) + sage: sorted(W.braid_orbit(word)) # optional - sage.combinat sage.groups [[0, 1, 2, 1], [0, 2, 1, 2], [2, 0, 1, 2]] - sage: sorted(W.braid_orbit([2,1,1,2,1])) + sage: sorted(W.braid_orbit([2,1,1,2,1])) # optional - sage.combinat sage.groups [[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 @@ -354,17 +354,17 @@ def __iter__(self): (2, 1, 2), (2, 1, 2, 1)] - sage: W = WeylGroup(["A",2,1]) - sage: g = iter(W) - sage: next(g) + 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 [1 0 0] [0 1 0] [0 0 1] - sage: next(g) + sage: next(g) # optional - sage.combinat sage.groups [-1 1 1] [ 0 1 0] [ 0 0 1] - sage: next(g) + sage: next(g) # optional - sage.combinat sage.groups [ 1 0 0] [ 1 -1 1] [ 0 0 1] @@ -377,19 +377,19 @@ def _element_constructor_(self, x, **args): EXAMPLES:: - sage: W1 = WeylGroup("G2",prefix="s") - sage: W2 = CoxeterGroup("G2") - sage: W3 = CoxeterGroup("G2", implementation="permutation") - sage: W1(W2.an_element()) + 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 s1*s2 - sage: W2(W1.an_element()) + sage: W2(W1.an_element()) # optional - sage.combinat sage.groups [ 2 -a] [ a -1] - sage: W1(W3.an_element()) + sage: W1(W3.an_element()) # optional - sage.combinat sage.groups s1*s2 - sage: s1,s2 = W1.simple_reflections() - sage: W = CoxeterGroup("A1") - sage: W(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 Traceback (most recent call last): ... ValueError: inconsistent number of rows: should be 1 but got 3 @@ -419,7 +419,7 @@ def weak_order_ideal(self, predicate, side="right", category=None): EXAMPLES:: sage: D6 = FiniteCoxeterGroups().example(5) - sage: I = D6.weak_order_ideal(predicate = lambda w: w.length() <= 3) + sage: I = D6.weak_order_ideal(predicate=lambda w: w.length() <= 3) sage: I.cardinality() 7 sage: list(I) @@ -511,17 +511,17 @@ def coxeter_element(self): EXAMPLES:: - sage: CoxeterGroup(['A', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['A', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: CoxeterGroup(['B', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['B', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: CoxeterGroup(['D', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['D', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 4, 3] - sage: CoxeterGroup(['F', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['F', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: CoxeterGroup(['E', 8]).coxeter_element().reduced_word() + sage: CoxeterGroup(['E', 8]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 3, 2, 4, 5, 6, 7, 8] - sage: CoxeterGroup(['H', 3]).coxeter_element().reduced_word() + sage: CoxeterGroup(['H', 3]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3] This method is also used for well generated finite complex @@ -545,9 +545,9 @@ def coxeter_element(self): TESTS:: - sage: WeylGroup(['A', 4]).coxeter_element().reduced_word() + sage: WeylGroup(['A', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: SymmetricGroup(3).coxeter_element() + sage: SymmetricGroup(3).coxeter_element() # optional - sage.combinat sage.groups (1,3,2) """ return self.prod(self.simple_reflections()) @@ -575,24 +575,24 @@ class is not unique and we only obtain one such class. TESTS:: - sage: W = SymmetricGroup(3) - sage: sorted(W.standard_coxeter_elements()) + sage: W = SymmetricGroup(3) # optional - sage.combinat sage.groups + sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups [(1,2,3), (1,3,2)] - sage: W = Permutations(3) - sage: sorted(W.standard_coxeter_elements()) + sage: W = Permutations(3) # optional - sage.combinat sage.groups + sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups [[2, 3, 1], [3, 1, 2]] - sage: W = CoxeterGroup(['D',3]) - sage: sorted(W.standard_coxeter_elements()) + sage: W = CoxeterGroup(['D', 3]) # optional - sage.combinat sage.groups + sage: sorted(W.standard_coxeter_elements()) # optional - 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) - sage: len(W.standard_coxeter_elements()) + sage: W = ColoredPermutations(3,2) # optional - sage.combinat sage.groups + sage: len(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups 2 """ if not self.is_irreducible() or not self.is_well_generated(): @@ -642,8 +642,9 @@ def fully_commutative_elements(self): EXAMPLES:: - sage: CoxeterGroup(['A', 3]).fully_commutative_elements() - Fully commutative elements of Finite Coxeter group over Integer Ring with Coxeter matrix: + sage: CoxeterGroup(['A', 3]).fully_commutative_elements() # optional - sage.combinat sage.groups + Fully commutative elements of + Finite Coxeter group over Integer Ring with Coxeter matrix: [1 3 2] [3 1 3] [2 3 1] @@ -689,7 +690,7 @@ def simple_projection(self, i, side='right', length_increasing=True): sage: sigma (1, 2, 3, 0) sage: u0 = W.simple_projection(0) - sage: d0 = W.simple_projection(0,length_increasing=False) + sage: d0 = W.simple_projection(0, length_increasing=False) sage: sigma.length() 3 sage: pi=sigma*s[0] @@ -738,9 +739,9 @@ 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') - sage: KL_cells = W.kazhdan_lusztig_cells(side='right') - sage: set([tuple(sorted(C, key=lambda w: w.reduced_word())) + 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 ....: for C in KL_cells]) {( [-1 1] [ 0 -1] @@ -758,11 +759,11 @@ def kazhdan_lusztig_cells(self, side='left'): [ 1 0] [-1 1] [ 1 -1], [-1 0] )} - sage: len(KL_cells) + sage: len(KL_cells) # optional - sage.combinat sage.groups 4 - sage: W = CoxeterGroup('A2', implementation='permutation') - sage: len(W.kazhdan_lusztig_cells(side='right')) + sage: W = CoxeterGroup('A2', implementation='permutation') # optional - sage.combinat sage.groups + sage: len(W.kazhdan_lusztig_cells(side='right')) # optional - sage.combinat sage.groups 4 We compute the left cells in the Coxeter group of type `A_3` @@ -792,11 +793,12 @@ def kazhdan_lusztig_cells(self, side='left'): 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: W = CoxeterGroup('B3', implementation='coxeter3') # optional - coxeter3 + sage: b3_cells = W.kazhdan_lusztig_cells('two-sided') # optional - coxeter3 + sage: len(b3_cells) # optional - coxeter3 6 - sage: set([tuple(sorted(C)) for C in W.kazhdan_lusztig_cells()]) # optional - coxeter3 + sage: set([tuple(sorted(C)) # optional - coxeter3 + ....: for C in W.kazhdan_lusztig_cells()]) {([],), ([1], [1, 2, 3, 2, 1], [2, 1], [2, 3, 2, 1], [3, 2, 1]), ([1, 2], [1, 2, 3, 2], [2], [2, 3, 2], [3, 2]), @@ -825,8 +827,8 @@ def kazhdan_lusztig_cells(self, side='left'): TESTS:: - sage: W = CoxeterGroup(['A', 2, 1]) - sage: W.kazhdan_lusztig_cells() + sage: W = CoxeterGroup(['A', 2, 1]) # optional - sage.combinat sage.groups + sage: W.kazhdan_lusztig_cells() # optional - sage.combinat sage.groups Traceback (most recent call last): ... ValueError: the Coxeter group must be finite to compute Kazhdan--Lusztig cells @@ -887,7 +889,9 @@ def simple_projections(self, side='right', length_increasing=True): sage: sigma = W.an_element(); sigma (1, 2, 3, 0) sage: pi = W.simple_projections(); pi - Finite family {0: at ...>, 1: at ...>, 2: ...>} + Finite family {0: at ...>, + 1: at ...>, + 2: ...>} sage: pi[1](sigma) (1, 3, 2, 0) sage: W.simple_projection(1)(sigma) @@ -907,9 +911,11 @@ def sign_representation(self, base_ring=None, side="twosided"): EXAMPLES:: - sage: W = WeylGroup(["A", 1, 1]) - sage: W.sign_representation() - Sign representation of Weyl Group of type ['A', 1, 1] (as a matrix group acting on the root space) over Integer Ring + sage: W = WeylGroup(["A", 1, 1]) # optional - sage.combinat sage.groups + sage: W.sign_representation() # optional - 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 """ if base_ring is None: @@ -933,18 +939,18 @@ def demazure_product(self, Q): EXAMPLES:: - sage: W = WeylGroup(['A',2]) - sage: w = W.demazure_product([2,2,1]) - sage: w.reduced_word() + 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 [2, 1] - sage: w = W.demazure_product([2,1,2,1,2]) - sage: w.reduced_word() + sage: w = W.demazure_product([2,1,2,1,2]) # optional - sage.combinat sage.groups + sage: w.reduced_word() # optional - sage.combinat sage.groups [1, 2, 1] - sage: W = WeylGroup(['B',2]) - sage: w = W.demazure_product([2,1,2,1,2]) - sage: w.reduced_word() + 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 [2, 1, 2, 1] """ return self.one().apply_demazure_product(Q) @@ -955,16 +961,16 @@ def bruhat_interval(self, x, y): EXAMPLES:: - sage: W = WeylGroup("A3", prefix="s") - sage: [s1,s2,s3] = W.simple_reflections() - sage: W.bruhat_interval(s2,s1*s3*s2*s1*s3) + 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 [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") - sage: [s0,s1,s2] = W.simple_reflections() - sage: W.bruhat_interval(1,s0*s1*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 [s0*s1*s2, s1*s2, s0*s2, s0*s1, s2, s1, s0, 1] """ if x == 1: @@ -994,19 +1000,19 @@ def bruhat_interval_poset(self, x, y, facade=False): EXAMPLES:: - sage: W = WeylGroup("A3", prefix="s") - sage: s1,s2,s3 = W.simple_reflections() - sage: W.bruhat_interval_poset(s2, s1*s3*s2*s1*s3) + 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 Finite poset containing 16 elements - sage: W = WeylGroup(['A',2,1], prefix="s") - sage: s0,s1,s2 = W.simple_reflections() - sage: W.bruhat_interval_poset(1, s0*s1*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_poset(1, s0*s1*s2) # optional - sage.combinat sage.groups Finite poset containing 8 elements TESTS:: - sage: W.bruhat_interval_poset(s0*s1*s2, s0*s1*s2) + sage: W.bruhat_interval_poset(s0*s1*s2, s0*s1*s2) # optional - sage.combinat sage.groups Finite poset containing 1 elements """ if x == 1: @@ -1061,27 +1067,27 @@ def bruhat_graph(self, x=None, y=None, edge_labels=False): EXAMPLES:: - sage: W = CoxeterGroup(['H',3]) - sage: G = W.bruhat_graph(); G + 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 Digraph on 120 vertices - sage: W = CoxeterGroup(['A',2,1]) - sage: s1, s2, s3 = W.simple_reflections() - sage: W.bruhat_graph(s1, s1*s3*s2*s3) + 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 Digraph on 6 vertices - sage: W.bruhat_graph(s1, s3*s2*s3) + sage: W.bruhat_graph(s1, s3*s2*s3) # optional - sage.combinat sage.groups sage.graphs Digraph on 0 vertices - sage: W = WeylGroup("A3", prefix="s") - sage: s1, s2, s3 = W.simple_reflections() - sage: G = W.bruhat_graph(s1*s3, s1*s2*s3*s2*s1); G + 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 Digraph on 10 vertices Check that the graph has the correct number of edges (see :trac:`17744`):: - sage: len(G.edges(sort=False)) + sage: len(G.edges(sort=False)) # optional - sage.combinat sage.groups sage.graphs 16 """ if x is None or x == 1: @@ -1129,8 +1135,8 @@ def canonical_representation(self): EXAMPLES:: - sage: W = WeylGroup("A3") - sage: W.canonical_representation() + sage: W = WeylGroup("A3") # optional - sage.combinat sage.groups + sage: W.canonical_representation() # optional - sage.combinat sage.groups Finite Coxeter group over Integer Ring with Coxeter matrix: [1 3 2] [3 1 3] @@ -1146,16 +1152,16 @@ def elements_of_length(self, n): EXAMPLES:: - sage: A = AffinePermutationGroup(['A',2,1]) - sage: [len(list(A.elements_of_length(i))) for i in [0..5]] + 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 [1, 3, 6, 9, 12, 15] - sage: W = CoxeterGroup(['H',3]) - sage: [len(list(W.elements_of_length(i))) for i in range(4)] + 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 [1, 3, 5, 7] - sage: W = CoxeterGroup(['A',2]) - sage: [len(list(W.elements_of_length(i))) for i in range(6)] + 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 [1, 2, 2, 1, 0, 0] """ I = self.weak_order_ideal(ConstantFunction(True), side='right') @@ -1173,18 +1179,18 @@ def random_element_of_length(self, n): EXAMPLES:: - sage: A = AffinePermutationGroup(['A', 7, 1]) - sage: p = A.random_element_of_length(10) - sage: p in A + 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 True - sage: p.length() == 10 + sage: p.length() == 10 # optional - sage.combinat sage.groups True - sage: W = CoxeterGroup(['A', 4]) - sage: p = W.random_element_of_length(5) - sage: p in W + 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 True - sage: p.length() == 5 + sage: p.length() == 5 # optional - sage.combinat sage.groups True """ from sage.misc.prandom import randint @@ -1236,14 +1242,14 @@ def _test_has_descent(self, **options): sage: W = CoxeterGroups().example() sage: W._test_has_descent() - 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 = 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: W = SignedPermutations(3) - sage: W._test_has_descent() + sage: W = SignedPermutations(3) # optional - sage.combinat sage.groups + sage: W._test_has_descent() # optional - sage.combinat sage.groups """ tester = self._tester(**options) s = self.simple_reflections() @@ -1300,21 +1306,21 @@ def _test_coxeter_relations(self, **options): TESTS:: - sage: A = AffinePermutationGroup(['A',7,1]) - sage: A._test_coxeter_relations() + sage: A = AffinePermutationGroup(['A', 7, 1]) # optional - sage.combinat sage.groups + sage: A._test_coxeter_relations() # optional - sage.combinat sage.groups - sage: cm = CartanMatrix([[2,-5,0],[-2,2,-1],[0,-1,2]]) - sage: W = WeylGroup(cm) - sage: W._test_coxeter_relations() + 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: 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 = 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: W = SignedPermutations(3) - sage: W._test_coxeter_relations() + sage: W = SignedPermutations(3) # optional - sage.combinat sage.groups + sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups """ tester = self._tester(**options) s = self.simple_reflections() @@ -1347,7 +1353,7 @@ def has_descent(self, i, side='right', positive=False): sage: w = s[0] * s[1] * s[2] sage: w.has_descent(2) True - sage: [ w.has_descent(i) for i in [0,1,2] ] + sage: [ w.has_descent(i) for i in [0,1,2] ] [False, False, True] sage: [ w.has_descent(i, side='left') for i in [0,1,2] ] [True, False, False] @@ -1600,17 +1606,18 @@ def reduced_words(self): sage: W = CoxeterGroups().example() sage: s = W.simple_reflections() sage: w = s[0] * s[2] - sage: sorted(w.reduced_words()) + sage: sorted(w.reduced_words()) # optional - sage.combinat [[0, 2], [2, 0]] - sage: W = WeylGroup(['E',6]) - sage: w = W.from_reduced_word([2,3,4,2]) - sage: sorted(w.reduced_words()) + 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 [[2, 3, 4, 2], [3, 2, 4, 2], [3, 4, 2, 4]] - sage: W = ReflectionGroup(['A',3], index_set=["AA","BB","5"]) # optional - gap3 - sage: w = W.long_element() # optional - gap3 - sage: w.reduced_words() # optional - gap3 + sage: W = ReflectionGroup(['A',3], # optional - gap3 + ....: index_set=["AA","BB","5"]) + sage: w = W.long_element() # optional - gap3 + sage: w.reduced_words() # optional - gap3 [['BB', '5', 'AA', 'BB', '5', 'AA'], ['5', 'BB', '5', 'AA', 'BB', '5'], ['BB', 'AA', 'BB', '5', 'BB', 'AA'], @@ -1693,32 +1700,32 @@ def reduced_word_graph(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix='s') - sage: w0 = W.long_element() - sage: G = w0.reduced_word_graph() - sage: G.num_verts() + 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 16 - sage: len(w0.reduced_words()) + sage: len(w0.reduced_words()) # optional - sage.combinat sage.groups sage.graphs 16 - sage: G.num_edges() + sage: G.num_edges() # optional - sage.combinat sage.groups sage.graphs 18 - sage: len([e for e in G.edges(sort=False) if e[2] == 2]) + sage: len([e for e in G.edges(sort=False) if e[2] == 2]) # optional - sage.combinat sage.groups sage.graphs 10 - sage: len([e for e in G.edges(sort=False) if e[2] == 3]) + sage: len([e for e in G.edges(sort=False) if e[2] == 3]) # optional - sage.combinat sage.groups sage.graphs 8 TESTS:: - sage: p = Permutation([3,2,4,1]) - sage: pp = WeylGroup(['A',3]).from_reduced_word(p.reduced_word()) - sage: pp.reduced_word_graph() + 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 Graph on 3 vertices - sage: w1 = W.one() - sage: G = w1.reduced_word_graph() - sage: G.num_verts() + 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 1 - sage: G.num_edges() + sage: G.num_edges() # optional - sage.combinat sage.groups sage.graphs 0 .. SEEALSO:: @@ -1814,14 +1821,14 @@ def reflection_length(self): EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: s = W.simple_reflections() - sage: (s[1]*s[2]*s[3]).reflection_length() + 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 3 - sage: W = SymmetricGroup(4) - sage: s = W.simple_reflections() - sage: (s[3]*s[2]*s[3]).reflection_length() + 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 1 """ @@ -1844,14 +1851,14 @@ def absolute_length(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) - sage: s = W.simple_reflections() - sage: (s[1]*s[2]*s[3]).absolute_length() + 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 3 - sage: W = SymmetricGroup(4) - sage: s = W.simple_reflections() - sage: (s[3]*s[2]*s[1]).absolute_length() + 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 3 """ M = self.canonical_matrix() @@ -1876,40 +1883,45 @@ def absolute_le(self, other): EXAMPLES:: - 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) + 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 True - sage: w1.absolute_le(w0) + sage: w1.absolute_le(w0) # optional - sage.combinat sage.groups False - sage: w1.absolute_le(w1) + sage: w1.absolute_le(w1) # optional - sage.combinat sage.groups True TESTS: Check that this is independent of the implementation of the group, see :trac:`34799`:: - sage: W1 = WeylGroup(['A',2]) - sage: W2 = Permutations(3) + sage: W1 = WeylGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: W2 = Permutations(3) # optional - sage.combinat sage.groups 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) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) - sage: d1 == d2 + sage: d1 = set((P(w1), P(w2)) for w1 in W1 for w2 in W1 # optional - sage.combinat sage.groups + ....: if w1.absolute_le(w2)) + sage: d2 = set((w1, w2) for w1 in W2 for w2 in W2 # optional - sage.combinat sage.groups + ....: if w1.absolute_le(w2)) + sage: d1 == d2 # optional - sage.combinat sage.groups True - 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 + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups + sage: d3 = set((w1, w2) # optional - sage.combinat sage.groups + ....: for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) + sage: d1 == d3 # optional - sage.combinat sage.groups True - sage: sage.combinat.permutation.Permutations.options._reset() - - 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) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) - sage: d1 == d2 + sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups + + 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 + ....: for w1 in W1 for w2 in W1 if w1.absolute_le(w2)) + sage: d2 = set((w1, w2) # optional - sage.combinat sage.groups + ....: for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) + sage: d1 == d2 # optional - sage.combinat sage.groups True """ if self == other: @@ -1928,11 +1940,11 @@ def absolute_covers(self): EXAMPLES:: - 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() + 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 [ [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] @@ -1956,9 +1968,9 @@ def canonical_matrix(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) - sage: s = W.simple_reflections() - sage: (s[1]*s[2]*s[3]).canonical_matrix() + 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 [ 0 0 -1] [ 1 0 -1] [ 0 1 -1] @@ -1988,11 +2000,11 @@ def coset_representative(self, index_set, side='right'): [2, 3] sage: w.coset_representative([1,2]).reduced_word() [2, 3] - sage: w.coset_representative([1,3] ).reduced_word() + sage: w.coset_representative([1,3] ).reduced_word() [2] - sage: w.coset_representative([2,3] ).reduced_word() + sage: w.coset_representative([2,3] ).reduced_word() [2, 1] - sage: w.coset_representative([1,2,3] ).reduced_word() + sage: w.coset_representative([1,2,3] ).reduced_word() [] sage: w.coset_representative([], side='left').reduced_word() [2, 3, 1] @@ -2039,15 +2051,15 @@ 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") - sage: v = W.from_reduced_word([1,2,3,4,3,1]) - sage: v + 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 s1*s2*s3*s4*s3*s1 - sage: v.apply_simple_projection(2) + sage: v.apply_simple_projection(2) # optional - sage.combinat sage.groups s1*s2*s3*s4*s3*s1*s2 - sage: v.apply_simple_projection(2, side='left') + sage: v.apply_simple_projection(2, side='left') # optional - sage.combinat sage.groups s1*s2*s3*s4*s3*s1 - sage: v.apply_simple_projection(1, length_increasing = False) + sage: v.apply_simple_projection(1, length_increasing=False) # optional - sage.combinat sage.groups s1*s2*s3*s4*s3 """ @@ -2075,44 +2087,50 @@ 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]) - sage: s = W.simple_reflections() - sage: w0 = W.from_reduced_word([1,2,3,1,2,1]) - sage: w0.binary_factorizations().cardinality() + 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 24 The same number of factorizations, by bounded length:: - sage: [w0.binary_factorizations(lambda u: u.length() <= l).cardinality() for l in [-1,0,1,2,3,4,5,6]] + sage: [w0.binary_factorizations( # optional - sage.combinat sage.groups + ....: lambda u: u.length() <= l + ....: ).cardinality() + ....: for l in [-1,0,1,2,3,4,5,6]] [0, 1, 4, 9, 15, 20, 23, 24] The number of factorizations of the elements just below the maximal element:: - sage: [(s[i]*w0).binary_factorizations().cardinality() for i in [1,2,3]] + sage: [(s[i]*w0).binary_factorizations().cardinality() # optional - sage.combinat sage.groups + ....: for i in [1,2,3]] [12, 12, 12] - sage: w0.binary_factorizations(lambda u: False).cardinality() + sage: w0.binary_factorizations(lambda u: False).cardinality() # optional - sage.combinat sage.groups 0 TESTS:: - sage: w0.binary_factorizations().category() + sage: w0.binary_factorizations().category() # optional - 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]) - 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} - sage: d1 == d2 + 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 + ....: 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 True - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" - sage: d3 = {pi: set(pi.binary_factorizations()) for pi in W2} - sage: d1 == d3 + 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 True - sage: sage.combinat.permutation.Permutations.options._reset() + sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups """ from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest W = self.parent() @@ -2142,35 +2160,38 @@ def bruhat_lower_covers(self): EXAMPLES:: - sage: W = WeylGroup(["A",3]) - sage: w = W.from_reduced_word([3,2,3]) - sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) + 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 [[3, 2], [2, 3]] - sage: W = WeylGroup(["A",3]) - sage: print([v.reduced_word() for v in W.simple_reflection(1).bruhat_lower_covers()]) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: print([v.reduced_word() # optional - sage.combinat sage.groups + ....: for v in W.simple_reflection(1).bruhat_lower_covers()]) [[]] - sage: print([v.reduced_word() for v in W.one().bruhat_lower_covers()]) + sage: print([v.reduced_word() # optional - sage.combinat sage.groups + ....: for v in W.one().bruhat_lower_covers()]) [] - 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()]) + 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 [[2], [0]] - sage: W = WeylGroup("A3",prefix="s",implementation="permutation") - sage: [s1,s2,s3]=W.simple_reflections() - sage: (s1*s2*s3*s1).bruhat_lower_covers() + 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 [s2*s1*s3, s1*s2*s1, s1*s2*s3] We now show how to construct the Bruhat poset:: - 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) - sage: P.show() + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: covers = tuple([u, v] # optional - sage.combinat sage.groups + ....: 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 Alternatively, one can just use:: - sage: P = W.bruhat_poset() + sage: P = W.bruhat_poset() # optional - sage.combinat sage.groups sage.graphs The algorithm is taken from Stembridge's 'coxeter/weyl' package for Maple. """ @@ -2193,21 +2214,21 @@ def bruhat_upper_covers(self): EXAMPLES:: - sage: W = WeylGroup(['A',3,1], prefix="s") - sage: w = W.from_reduced_word([1,2,1]) - sage: w.bruhat_upper_covers() + 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 [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]) - sage: w = W.long_element() - sage: w.bruhat_upper_covers() + 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]) - 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) + 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 True """ Covers = set() @@ -2231,17 +2252,17 @@ def bruhat_lower_covers_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.bruhat_lower_covers_reflections() + 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 [(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') - sage: W.w0.bruhat_lower_covers_reflections() + sage: W = CoxeterGroup(['A', 3], implementation='permutation') # optional - sage.combinat sage.groups + sage: W.w0.bruhat_lower_covers_reflections() # optional - 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))] @@ -2264,11 +2285,11 @@ def lower_cover_reflections(self, side='right'): EXAMPLES:: - sage: W = WeylGroup(['A',3],prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.lower_cover_reflections() + 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 [s1*s2*s3*s2*s1, s2, s1] - sage: w.lower_cover_reflections(side='left') + sage: w.lower_cover_reflections(side='left') # optional - sage.combinat sage.groups [s2*s3*s2, s3, s1] """ @@ -2287,10 +2308,11 @@ def bruhat_upper_covers_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',4], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.bruhat_upper_covers_reflections() - [(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)] + 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 + [(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)] """ Covers = set() for i in self.parent().index_set(): @@ -2310,11 +2332,11 @@ def cover_reflections(self, side='right'): EXAMPLES:: - sage: W = WeylGroup(['A',4], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.cover_reflections() + 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 [s3, s2*s3*s2, s4, s1*s2*s3*s4*s3*s2*s1] - sage: w.cover_reflections(side='left') + sage: w.cover_reflections(side='left') # optional - sage.combinat sage.groups [s4, s2, s1*s2*s1, s3*s4*s3] """ @@ -2335,19 +2357,19 @@ def bruhat_le(self, other): EXAMPLES:: - 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) + 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 True - sage: u.bruhat_le(v) + sage: u.bruhat_le(v) # optional - sage.combinat sage.groups True - sage: v.bruhat_le(u) + sage: v.bruhat_le(u) # optional - sage.combinat sage.groups False - sage: v.bruhat_le(v) + sage: v.bruhat_le(v) # optional - sage.combinat sage.groups True - sage: s = W.simple_reflections() - sage: s[1].bruhat_le(W.one()) + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: s[1].bruhat_le(W.one()) # optional - sage.combinat sage.groups False The implementation uses the equivalent condition that any @@ -2368,19 +2390,21 @@ def bruhat_le(self, other): We now run consistency tests with permutations and :meth:`bruhat_lower_covers`:: - sage: W = WeylGroup(["A",3]) - sage: P4 = Permutations(4) + 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()) - sage: for u in P4: + sage: for u in P4: # optional - sage.combinat sage.groups ....: for v in P4: ....: assert u.bruhat_lequal(v) == P4toW(u).bruhat_le(P4toW(v)) - 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) for u in W for v in W ) # long time (7s) + 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 + ....: for u in W for v in W) True - sage: all( P.is_lequal(u,v) == Q.is_lequal(u,v) for u in W for v in W) # long time (9s) + sage: all(P.is_lequal(u,v) == Q.is_lequal(u,v) # long time (9s) # optional - sage.combinat sage.groups sage.graphs + ....: for u in W for v in W) True """ if not have_same_parent(self, other): @@ -2409,21 +2433,21 @@ def weak_le(self, other, side='right'): EXAMPLES:: - 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) + 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 True - sage: u.weak_le(v) + sage: u.weak_le(v) # optional - sage.combinat sage.groups True - sage: v.weak_le(u) + sage: v.weak_le(u) # optional - sage.combinat sage.groups False - sage: v.weak_le(v) + sage: v.weak_le(v) # optional - sage.combinat sage.groups True Comparison for left weak order is achieved with the option ``side``:: - sage: u.weak_le(v, side='left') + sage: u.weak_le(v, side='left') # optional - sage.combinat sage.groups False The implementation uses the equivalent condition that any @@ -2439,10 +2463,10 @@ def weak_le(self, other, side='right'): We now run consistency tests with permutations:: - sage: W = WeylGroup(["A",3]) - 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) + 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 ....: 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') @@ -2475,29 +2499,29 @@ def weak_covers(self, side='right', index_set=None, positive=False): EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: w = W.from_reduced_word([3,2,1]) - sage: [x.reduced_word() for x in w.weak_covers()] + 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 [[3, 2]] To obtain instead elements that cover self, set ``positive=True``:: - sage: [x.reduced_word() for x in w.weak_covers(positive=True)] + sage: [x.reduced_word() for x in w.weak_covers(positive=True)] # optional - 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')] + sage: [x.reduced_word() for x in w.weak_covers(side='left')] # optional - sage.combinat sage.groups [[2, 1]] - sage: w = W.from_reduced_word([3,2,3,1]) - sage: [x.reduced_word() for x in w.weak_covers()] + 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 [[2, 3, 2], [3, 2, 1]] - sage: [x.reduced_word() for x in w.weak_covers(side='left')] + sage: [x.reduced_word() for x in w.weak_covers(side='left')] # optional - sage.combinat sage.groups [[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])] + sage: [x.reduced_word() for x in w.weak_covers(index_set=[1,2])] # optional - sage.combinat sage.groups [[2, 3, 2]] """ return [self.apply_simple_reflection(i, side=side) @@ -2580,16 +2604,20 @@ def is_coxeter_sortable(self, c, sorting_word=None): [2, 0, 1, 2, 0] sage: w.is_coxeter_sortable(c) True - sage: W = CoxeterGroup(['A',3]) - sage: c = W.from_reduced_word([1,2,3]) - sage: len([w for w in W if w.is_coxeter_sortable(c)]) # number of c-sortable elements in A_3 (Catalan number) + + sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: c = W.from_reduced_word([1,2,3]) # optional - 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 14 TESTS:: - sage: W = SymmetricGroup(3) - sage: c = Permutation((1,2,3)) - sage: sorted(w for w in W if w.is_coxeter_sortable(c)) + 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 [(), (2,3), (1,2), (1,3,2), (1,3)] """ if hasattr(c, "reduced_word"): @@ -2640,15 +2668,15 @@ def apply_demazure_product(self, element, side='right', EXAMPLES:: - 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]) + 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 s4*s1*s2*s3*s4*s3*s1 - sage: v.apply_demazure_product([1,3,4,3],side='left') + sage: v.apply_demazure_product([1,3,4,3], side='left') # optional - sage.combinat sage.groups s3*s4*s1*s2*s3*s4*s2*s3*s1 - sage: v.apply_demazure_product((1,3,4,3),side='left') + sage: v.apply_demazure_product((1,3,4,3), side='left') # optional - sage.combinat sage.groups s3*s4*s1*s2*s3*s4*s2*s3*s1 - sage: v.apply_demazure_product(v) + sage: v.apply_demazure_product(v) # optional - sage.combinat sage.groups s2*s3*s4*s1*s2*s3*s4*s2*s3*s2*s1 """ @@ -2683,14 +2711,14 @@ def min_demazure_product_greater(self, element): EXAMPLES:: - 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) + 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 s4*s2 - sage: v.min_demazure_product_greater([2,3,2,1]) + sage: v.min_demazure_product_greater([2,3,2,1]) # optional - sage.combinat sage.groups s4*s2 - sage: v.min_demazure_product_greater((2,3,2,1)) + sage: v.min_demazure_product_greater((2,3,2,1)) # optional - sage.combinat sage.groups s4*s2 """ @@ -2730,14 +2758,14 @@ def deodhar_factor_element(self, w, index_set): EXAMPLES:: - 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]) + 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 s3*s1 - sage: W = WeylGroup(['C',2]) - sage: w = W.from_reduced_word([2,1]) - sage: w.deodhar_factor_element(W.from_reduced_word([2]),[1]) + 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 Traceback (most recent call last): ... ValueError: [2, 1] is not of minimum length in its coset for the parabolic subgroup with index set [1] @@ -2785,10 +2813,10 @@ def deodhar_lift_up(self, w, index_set): EXAMPLES:: - 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]) + 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 s1*s2*s3*s2 """ vmin = self.coset_representative(index_set) @@ -2819,10 +2847,10 @@ def deodhar_lift_down(self, w, index_set): EXAMPLES:: - 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]) + 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 s2*s3*s2 """ @@ -2842,9 +2870,9 @@ def inversions_as_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.inversions_as_reflections() + 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 [s1, s1*s2*s1, s2, s1*s2*s3*s2*s1] """ i = self.first_descent() @@ -2859,9 +2887,9 @@ def left_inversions_as_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.left_inversions_as_reflections() + 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 [s1, s3, s1*s2*s3*s2*s1, s2*s3*s2] """ return self.inverse().inversions_as_reflections() @@ -2872,31 +2900,31 @@ def lower_covers(self, side='right', index_set=None): INPUT: - - side -- 'left' or 'right' (default: 'right') - - index_set -- a list of indices or ``None`` + - ``side`` -- ``'left'`` or ``'right'`` (default: ``'right'``) + - ``index_set`` -- a list of indices or ``None`` OUTPUT: a list EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: w = W.from_reduced_word([3,2,1]) - sage: [x.reduced_word() for x in w.lower_covers()] + 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 [[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')] + sage: [x.reduced_word() for x in w.lower_covers(side='left')] # optional - sage.combinat sage.groups [[2, 1]] - sage: w = W.from_reduced_word([3,2,3,1]) - sage: [x.reduced_word() for x in w.lower_covers()] + 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 [[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])] + sage: [x.reduced_word() for x in w.lower_covers(index_set=[1,2])] # optional - sage.combinat sage.groups [[2, 3, 2]] - sage: [x.reduced_word() for x in w.lower_covers(side='left')] + sage: [x.reduced_word() for x in w.lower_covers(side='left')] # optional - sage.combinat sage.groups [[3, 2, 1], [2, 3, 1]] """ return self.weak_covers(side=side, index_set=index_set, @@ -2908,28 +2936,29 @@ def upper_covers(self, side='right', index_set=None): INPUT: - - side -- 'left' or 'right' (default: 'right') - - index_set -- a list of indices or None + - ``side`` -- ``'left'`` or ``'right'`` (default: ``'right'``) + - ``index_set`` -- a list of indices or ``None`` OUTPUT: a list EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: w = W.from_reduced_word([2,3]) - sage: [x.reduced_word() for x in w.upper_covers()] + 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 [[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')] + sage: [x.reduced_word() for x in w.upper_covers(side='left')] # optional - 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])] + sage: [x.reduced_word() for x in w.upper_covers(index_set=[1])] # optional - sage.combinat sage.groups [[2, 3, 1]] - sage: [x.reduced_word() for x in w.upper_covers(side='left', index_set = [1])] + sage: [x.reduced_word() # optional - sage.combinat sage.groups + ....: for x in w.upper_covers(side='left', index_set=[1])] [[1, 2, 3]] """ return self.weak_covers(side=side, index_set=index_set, @@ -2972,9 +3001,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') - sage: s1,s2,s3 = W.simple_reflections() - sage: s1.kazhdan_lusztig_cell() + 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 {(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)} diff --git a/src/sage/categories/crystals.py b/src/sage/categories/crystals.py index f74340cf25d..3ceb16529d6 100644 --- a/src/sage/categories/crystals.py +++ b/src/sage/categories/crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs sage.combinat r""" Crystals diff --git a/src/sage/categories/discrete_valuation.py b/src/sage/categories/discrete_valuation.py index 5b68f8b6c12..42829732859 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() + sage: GF(7)[['x']] in DiscreteValuationRings() # optional - sage.rings.finite_rings True sage: TestSuite(DiscreteValuationRings()).run() """ @@ -41,7 +41,7 @@ def uniformizer(self): EXAMPLES:: - sage: Zp(5).uniformizer() + sage: Zp(5).uniformizer() # optional - sage.rings.padics 5 + O(5^21) sage: K. = QQ[[]] @@ -56,7 +56,7 @@ def residue_field(self): EXAMPLES:: - sage: Zp(5).residue_field() + sage: Zp(5).residue_field() # optional - sage.rings.padics Finite Field of size 5 sage: K. = QQ[[]] @@ -70,38 +70,38 @@ def _matrix_charpoly(self, M, var): EXAMPLES:: - 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 + 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 + ....: for i in range(4) for j in range(4)]) + sage: M # optional - sage.rings.finite_rings [ 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 + sage: M.charpoly() # indirect doctest # optional - sage.rings.finite_rings 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 ]) - sage: M + 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 [ 1 t t^2] [1 + t t^2 t^3] [ t^2 t^3 t^4] - sage: M.charpoly() + sage: M.charpoly() # optional - sage.rings.finite_rings 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) - sage: M = matrix(R, 3, 3, range(9)) - sage: M + 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 [ 0 ...00001 ...00002] [ ...00003 ...00004 ...000010] [ ...00011 ...00012 ...00013] - sage: M.charpoly() + sage: M.charpoly() # optional - sage.rings.padics ...00001*x^3 + ...44423*x^2 + ...44412*x + ...00000 """ return M._charpoly_hessenberg(var) @@ -114,8 +114,8 @@ def valuation(self): EXAMPLES:: - sage: x = Zp(5)(50) - sage: x.valuation() + sage: x = Zp(5)(50) # optional - sage.rings.padics + sage: x.valuation() # optional - sage.rings.padics 2 """ @@ -125,10 +125,10 @@ def euclidean_degree(self): TESTS:: - sage: R. = GF(5)[[]] - sage: (q^3).euclidean_degree() + sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: (q^3).euclidean_degree() # optional - sage.rings.finite_rings 3 - sage: R(0).euclidean_degree() + sage: R(0).euclidean_degree() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: Euclidean degree of the zero element not defined @@ -145,12 +145,12 @@ def quo_rem(self, other): TESTS:: - sage: R. = GF(5)[[]] - sage: (q^2 + q).quo_rem(q) + sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: (q^2 + q).quo_rem(q) # optional - sage.rings.finite_rings (1 + q, 0) - sage: (q + 1).quo_rem(q^2) + sage: (q + 1).quo_rem(q^2) # optional - sage.rings.finite_rings (0, 1 + q) - sage: q.quo_rem(0) + sage: q.quo_rem(0) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: Euclidean division by the zero element not defined @@ -170,12 +170,12 @@ def is_unit(self): EXAMPLES:: - sage: x = Zp(5)(50) - sage: x.is_unit() + sage: x = Zp(5)(50) # optional - sage.rings.padics + sage: x.is_unit() # optional - sage.rings.padics False - sage: x = Zp(7)(50) - sage: x.is_unit() + sage: x = Zp(7)(50) # optional - sage.rings.padics + sage: x.is_unit() # optional - sage.rings.padics True """ return self.valuation() == 0 @@ -213,7 +213,7 @@ class DiscreteValuationFields(Category_singleton): EXAMPLES:: - sage: Qp(7) in DiscreteValuationFields() + sage: Qp(7) in DiscreteValuationFields() # optional - sage.rings.padics True sage: TestSuite(DiscreteValuationFields()).run() """ @@ -235,7 +235,7 @@ def uniformizer(self): EXAMPLES:: - sage: Qp(5).uniformizer() + sage: Qp(5).uniformizer() # optional - sage.rings.padics 5 + O(5^21) """ @@ -247,7 +247,7 @@ def residue_field(self): EXAMPLES:: - sage: Qp(5).residue_field() + sage: Qp(5).residue_field() # optional - sage.rings.padics Finite Field of size 5 sage: K. = LaurentSeriesRing(QQ) @@ -261,17 +261,17 @@ def _matrix_hessenbergize(self, H): EXAMPLES:: - 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 + 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 + ....: for i in range(4) for j in range(4)]) + sage: H # optional - sage.rings.finite_rings [ 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() - sage: H + sage: H.hessenbergize() # optional - sage.rings.finite_rings + sage: H # optional - sage.rings.finite_rings [ 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 +279,14 @@ def _matrix_hessenbergize(self, H): Another example over the p-adics:: - sage: K = Qp(5, print_mode="digits", prec=5) - sage: H = matrix(K, 3, 3, range(9)) - sage: H + 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 [ 0 ...00001 ...00002] [ ...00003 ...00004 ...000010] [ ...00011 ...00012 ...00013] - sage: H.hessenbergize() - sage: H + sage: H.hessenbergize() # optional - sage.rings.padics + sage: H # optional - sage.rings.padics [ 0 ...00010 ...00002] [ ...00003 ...00024 ...000010] [ ...00000 ...44440 ...44443] @@ -302,7 +302,7 @@ def valuation(self): EXAMPLES:: - sage: x = Qp(5)(50) - sage: x.valuation() + sage: x = Qp(5)(50) # optional - sage.rings.padics + sage: x.valuation() # optional - sage.rings.padics 2 """ diff --git a/src/sage/categories/domains.py b/src/sage/categories/domains.py index c40f95ba880..02062390a02 100644 --- a/src/sage/categories/domains.py +++ b/src/sage/categories/domains.py @@ -59,21 +59,21 @@ 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 + sage: R = ZpFM(5); R # optional - sage.rings.padics 5-adic Ring of fixed modulus 5^20 - sage: R.is_exact() + sage: R.is_exact() # optional - sage.rings.padics False - sage: a = R(5^19) - sage: a.is_zero() + sage: a = R(5^19) # optional - sage.rings.padics + sage: a.is_zero() # optional - sage.rings.padics False - sage: (a*a).is_zero() + sage: (a * a).is_zero() # optional - sage.rings.padics True - sage: R._test_zero_divisors() + sage: R._test_zero_divisors() # optional - sage.rings.padics EXAMPLES:: sage: ZZ._test_zero_divisors() - sage: ZpFM(5)._test_zero_divisors() + sage: ZpFM(5)._test_zero_divisors() # optional - 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 4a4f193bf1c..2ae9eb54173 100644 --- a/src/sage/categories/drinfeld_modules.py +++ b/src/sage/categories/drinfeld_modules.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 1097a04412a..b58cb646aba 100644 --- a/src/sage/categories/enumerated_sets.py +++ b/src/sage/categories/enumerated_sets.py @@ -85,7 +85,8 @@ class EnumeratedSets(CategoryWithAxiom): sage: EnumeratedSets().super_categories() [Category of sets] sage: EnumeratedSets().all_super_categories() - [Category of enumerated sets, Category of sets, Category of sets with partial maps, Category of objects] + [Category of enumerated sets, Category of sets, + Category of sets with partial maps, Category of objects] TESTS:: @@ -277,33 +278,33 @@ def iterator_range(self, start=None, stop=None, step=None): EXAMPLES:: - sage: P = Partitions() - sage: list(P.iterator_range(stop=5)) + sage: P = Partitions() # optional - sage.combinat + sage: list(P.iterator_range(stop=5)) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: list(P.iterator_range(0, 5)) + sage: list(P.iterator_range(0, 5)) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: list(P.iterator_range(3, 5)) + sage: list(P.iterator_range(3, 5)) # optional - sage.combinat [[1, 1], [3]] - sage: list(P.iterator_range(3, 10)) + sage: list(P.iterator_range(3, 10)) # optional - sage.combinat [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: list(P.iterator_range(3, 10, 2)) + sage: list(P.iterator_range(3, 10, 2)) # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2]] - sage: it = P.iterator_range(3) - sage: [next(it) for x in range(10)] + sage: it = P.iterator_range(3) # optional - sage.combinat + sage: [next(it) for x in range(10)] # optional - sage.combinat [[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) - sage: [next(it) for x in range(5)] + sage: it = P.iterator_range(3, step=2) # optional - sage.combinat + sage: [next(it) for x in range(5)] # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2], [1, 1, 1, 1]] - sage: next(P.iterator_range(stop=-3)) + sage: next(P.iterator_range(stop=-3)) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: next(P.iterator_range(start=-3)) + sage: next(P.iterator_range(start=-3)) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -356,26 +357,26 @@ def unrank_range(self, start=None, stop=None, step=None): EXAMPLES:: - sage: P = Partitions() - sage: P.unrank_range(stop=5) + sage: P = Partitions() # optional - sage.combinat + sage: P.unrank_range(stop=5) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P.unrank_range(0, 5) + sage: P.unrank_range(0, 5) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P.unrank_range(3, 5) + sage: P.unrank_range(3, 5) # optional - sage.combinat [[1, 1], [3]] - sage: P.unrank_range(3, 10) + sage: P.unrank_range(3, 10) # optional - sage.combinat [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: P.unrank_range(3, 10, 2) + sage: P.unrank_range(3, 10, 2) # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2]] - sage: P.unrank_range(3) + sage: P.unrank_range(3) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P.unrank_range(stop=-3) + sage: P.unrank_range(stop=-3) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P.unrank_range(start=-3) + sage: P.unrank_range(start=-3) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -409,24 +410,24 @@ def __getitem__(self, i): EXAMPLES:: - sage: P = Partitions() - sage: P[:5] + sage: P = Partitions() # optional - sage.combinat + sage: P[:5] # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P[0:5] + sage: P[0:5] # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P[3:5] + sage: P[3:5] # optional - sage.combinat [[1, 1], [3]] - sage: P[3:10] + sage: P[3:10] # optional - sage.combinat [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: P[3:10:2] + sage: P[3:10:2] # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2]] - sage: P[3:] + sage: P[3:] # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P[3] + sage: P[3] # optional - sage.combinat [1, 1] - sage: P[-1] + sage: P[-1] # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -467,9 +468,9 @@ def __len__(self): EXAMPLES:: - sage: len(GF(5)) + sage: len(GF(5)) # optional - sage.libs.pari 5 - sage: len(MatrixSpace(GF(2), 3, 3)) + sage: len(MatrixSpace(GF(2), 3, 3)) # optional - sage.libs.pari sage.modules 512 """ from sage.rings.infinity import Infinity @@ -494,7 +495,7 @@ def tuple(self): EXAMPLES:: - sage: (GF(3)^2).tuple() + sage: (GF(3)^2).tuple() # optional - sage.libs.pari ((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 @@ -575,7 +576,7 @@ def list(self): EXAMPLES:: - sage: (GF(3)^2).list() + sage: (GF(3)^2).list() # optional - sage.libs.pari [(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() @@ -603,7 +604,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 + sage: (QQ^2).list() # indirect test # optional - sage.modules Traceback (most recent call last): ... AttributeError: 'FreeModule_ambient_field_with_category' object has no attribute 'list' @@ -958,16 +959,16 @@ def map(self, f, name=None, *, is_injective=True): EXAMPLES:: - sage: R = Compositions(4).map(attrcall('partial_sums')); R + sage: R = Compositions(4).map(attrcall('partial_sums')); R # optional - sage.combinat Image of Compositions of 4 by The map *.partial_sums() from Compositions of 4 - sage: R.cardinality() + sage: R.cardinality() # optional - sage.combinat 8 - sage: R.list() + sage: R.list() # optional - sage.combinat [[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] + sage: [r for r in R] # optional - sage.combinat [[1, 2, 3, 4], [1, 2, 4], [1, 3, 4], [1, 4], [2, 3, 4], [2, 4], [3, 4], [4]] - sage: R.category() + sage: R.category() # optional - sage.combinat Category of finite enumerated subobjects of sets .. WARNING:: @@ -975,20 +976,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) - sage: P.list() + sage: P = Compositions(4) # optional - sage.combinat + sage: P.list() # optional - sage.combinat [[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() + sage: P.map(attrcall('major_index')).list() # optional - sage.combinat [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() + sage: P.map(attrcall('major_index'), is_injective=False).list() # optional - sage.combinat [6, 3, 4, 1, 5, 2, 0] TESTS:: - sage: TestSuite(R).run(skip=['_test_an_element', + sage: TestSuite(R).run(skip=['_test_an_element', # optional - sage.combinat ....: '_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 f1d05839e2a..ccbc3a3a9c0 100644 --- a/src/sage/categories/examples/algebras_with_basis.py +++ b/src/sage/categories/examples/algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Examples of algebras with basis """ diff --git a/src/sage/categories/examples/crystals.py b/src/sage/categories/examples/crystals.py index 02121cd3c02..c38117b3b70 100644 --- a/src/sage/categories/examples/crystals.py +++ b/src/sage/categories/examples/crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 0b5e9b475eb..3cf9db3f57c 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 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.combinat r""" Examples of filtered modules with basis """ diff --git a/src/sage/categories/examples/finite_coxeter_groups.py b/src/sage/categories/examples/finite_coxeter_groups.py index c7937688ef8..57ada2a0c2b 100644 --- a/src/sage/categories/examples/finite_coxeter_groups.py +++ b/src/sage/categories/examples/finite_coxeter_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 f51b66c49dd..ac18f69b6ec 100644 --- a/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 a975d902e14..db28f48dff7 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,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Examples of a finite dimensional Lie algebra with basis """ diff --git a/src/sage/categories/examples/finite_semigroups.py b/src/sage/categories/examples/finite_semigroups.py index e21a9713815..bf00b415b58 100644 --- a/src/sage/categories/examples/finite_semigroups.py +++ b/src/sage/categories/examples/finite_semigroups.py @@ -25,7 +25,8 @@ class LeftRegularBand(UniqueRepresentation, Parent): EXAMPLES:: sage: S = FiniteSemigroups().example(); S - An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd') + An example of a finite semigroup: + the left regular band generated by ('a', 'b', 'c', 'd') This is the semigroup generated by:: @@ -69,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() + sage: S.cayley_graph(side="left", simple=True).plot() # optional - sage.graphs Graphics object consisting of 60 graphics primitives - sage: S.j_transversal_of_idempotents() # random (arbitrary choice) + sage: S.j_transversal_of_idempotents() # random (arbitrary choice) # optional - 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 535d5101101..b4d6c05a233 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() + sage: S.cayley_graph(side="left").plot() # optional - 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() + sage: TestSuite(S).run() # optional - sage.combinat """ def __init__(self, n=4): @@ -135,7 +135,7 @@ def cartan_type(self): EXAMPLES:: - sage: FiniteWeylGroups().example().cartan_type() + sage: FiniteWeylGroups().example().cartan_type() # optional - sage.combinat ['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 b67e01a4b02..2d2a0f71f4b 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,3 +1,4 @@ +# sage.doctest: optional - 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 0be39623fa3..86aa957c404 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 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.combinat r""" Examples of graded modules with basis """ diff --git a/src/sage/categories/examples/hopf_algebras_with_basis.py b/src/sage/categories/examples/hopf_algebras_with_basis.py index 35b61f3c085..265ab46836f 100644 --- a/src/sage/categories/examples/hopf_algebras_with_basis.py +++ b/src/sage/categories/examples/hopf_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 135a665cfa3..81c7f8457ab 100644 --- a/src/sage/categories/examples/lie_algebras.py +++ b/src/sage/categories/examples/lie_algebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Examples of a Lie algebra """ @@ -68,11 +69,11 @@ def __classcall_private__(cls, gens): EXAMPLES:: - 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 + 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 True """ return super().__classcall__(cls, tuple(gens)) @@ -81,8 +82,8 @@ def __init__(self, gens): """ EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: TestSuite(L).run() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat + sage: TestSuite(L).run() # optional - sage.combinat """ if not gens: raise ValueError("need at least one generator") @@ -95,7 +96,7 @@ def _repr_(self): """ EXAMPLES:: - sage: LieAlgebras(QQ).example() + sage: LieAlgebras(QQ).example() # optional - 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]) @@ -110,10 +111,10 @@ def _element_constructor_(self, value): EXAMPLES:: - sage: S3 = SymmetricGroupAlgebra(ZZ, 3) - sage: gens = S3.algebra_generators() - sage: L = LieAlgebras(QQ).example() - sage: L(3*gens[0] + gens[1]) + 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 3*[2, 1, 3] + [2, 3, 1] """ return self.element_class(self, self._A(value)) @@ -124,8 +125,8 @@ def zero(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.zero() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: L.zero() # optional - sage.combinat sage.groups 0 """ return self.element_class(self, self._A.zero()) @@ -136,8 +137,8 @@ def lie_algebra_generators(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.lie_algebra_generators() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: L.lie_algebra_generators() # optional - sage.combinat sage.groups Family ([2, 1, 3], [2, 3, 1]) """ return Family([self.element_class(self, g) for g in self._gens]) @@ -157,17 +158,17 @@ def __eq__(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x == x + 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 True - sage: x.bracket(y) == -y.bracket(x) + sage: x.bracket(y) == -y.bracket(x) # optional - sage.combinat sage.groups True - sage: x == y + sage: x == y # optional - sage.combinat sage.groups False - sage: x.bracket(x) == L.zero() + sage: x.bracket(x) == L.zero() # optional - sage.combinat sage.groups True - sage: x.bracket(x) == 0 + sage: x.bracket(x) == 0 # optional - sage.combinat sage.groups True """ if not isinstance(rhs, LieAlgebraFromAssociative.Element): @@ -180,15 +181,15 @@ def __ne__(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x != y + 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 True - sage: x != 0 + sage: x != 0 # optional - sage.combinat sage.groups True - sage: x != x + sage: x != x # optional - sage.combinat sage.groups False - sage: x.bracket(y) != -y.bracket(x) + sage: x.bracket(y) != -y.bracket(x) # optional - sage.combinat sage.groups False """ return not self.__eq__(rhs) @@ -199,10 +200,10 @@ def __bool__(self) -> bool: EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: bool(sum(L.lie_algebra_generators())) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: bool(sum(L.lie_algebra_generators())) # optional - sage.combinat sage.groups True - sage: bool(L.zero()) + sage: bool(L.zero()) # optional - sage.combinat sage.groups False """ return bool(self.value) @@ -213,9 +214,9 @@ def _add_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x + y + 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 [2, 1, 3] + [2, 3, 1] """ return self.__class__(self.parent(), self.value + rhs.value) @@ -226,9 +227,9 @@ def _sub_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x - y + 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 [2, 1, 3] - [2, 3, 1] """ return self.__class__(self.parent(), self.value - rhs.value) @@ -239,9 +240,9 @@ def _acted_upon_(self, scalar, self_on_left=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: 3 * x + 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 3*[2, 1, 3] """ # This was copied, but IDK if it still applies: @@ -265,9 +266,9 @@ def __truediv__(self, x, self_on_left=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: y / 4 + 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 1/4*[2, 3, 1] """ if self_on_left: @@ -280,9 +281,9 @@ def __neg__(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: -x + 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 -[2, 1, 3] """ return self.__class__(self.parent(), -self.value) @@ -313,15 +314,15 @@ def _bracket_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: elt = 2*x - y - sage: elt.bracket(elt) + 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 0 - sage: elt.bracket(x) + sage: elt.bracket(x) # optional - sage.combinat sage.groups -[1, 3, 2] + [3, 2, 1] - sage: elt2 = x.bracket(y) + x - sage: elt.bracket(elt2) + sage: elt2 = x.bracket(y) + x # optional - sage.combinat sage.groups + sage: elt.bracket(elt2) # optional - sage.combinat sage.groups -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 484e0eee918..e69711ddf03 100644 --- a/src/sage/categories/examples/lie_algebras_with_basis.py +++ b/src/sage/categories/examples/lie_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 19b1ef29ade..6f358929a72 100644 --- a/src/sage/categories/examples/sets_cat.py +++ b/src/sage/categories/examples/sets_cat.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 7bc940dd289..627bd2a07c3 100644 --- a/src/sage/categories/examples/with_realizations.py +++ b/src/sage/categories/examples/with_realizations.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 4bbbd08ae95..28a93a314b5 100644 --- a/src/sage/categories/fields.py +++ b/src/sage/categories/fields.py @@ -38,7 +38,7 @@ class Fields(CategoryWithAxiom): sage: K(IntegerRing()) Rational Field - sage: K(PolynomialRing(GF(3), 'x')) + sage: K(PolynomialRing(GF(3), 'x')) # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 3 sage: K(RealField()) @@ -64,7 +64,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in Fields() + sage: GF(4, "a") in Fields() # optional - 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() + sage: gap.Rationals in Fields() # optional - sage.libs.gap False typically by implementing the method :meth:`category` appropriately for Gap objects:: - sage: GR = gap.Rationals - sage: GR.category = lambda : Fields() - sage: GR in Fields() + 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 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): + sage: for i in prime_range(100): # optional - sage.libs.pari ....: R = ZZ.quotient(i) ....: t = R in Fields() @@ -140,16 +140,16 @@ def _contains_helper(cls): TESTS:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) - sage: Q.category() + sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari + sage: Q.category() # optional - sage.libs.pari 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) + sage: F._contains_helper(Q) # optional - sage.libs.pari False - sage: Q in F # This changes the category! + sage: Q in F # This changes the category! # optional - sage.libs.pari True - sage: F._contains_helper(Q) + sage: F._contains_helper(Q) # optional - sage.libs.pari True """ @@ -169,7 +169,7 @@ def _call_(self, x): sage: K(IntegerRing()) # indirect doctest Rational Field - sage: K(PolynomialRing(GF(3), 'x')) # indirect doctest + sage: K(PolynomialRing(GF(3), 'x')) # indirect doctest # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 3 sage: K(RealField()) @@ -207,11 +207,11 @@ def is_integrally_closed(self): sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() + sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field True - sage: Z5 = GF(5); Z5 + sage: Z5 = GF(5); Z5 # optional - sage.rings.finite_rings Finite Field of size 5 - sage: Z5.is_integrally_closed() + sage: Z5.is_integrally_closed() # optional - sage.rings.finite_rings True """ return True @@ -231,13 +231,15 @@ def _gcd_univariate_polynomial(self, a, b): EXAMPLES:: - sage: R. = QQbar[] - sage: QQbar._gcd_univariate_polynomial(2*x, 2*x^2) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: QQbar._gcd_univariate_polynomial(2*x, 2*x^2) # optional - sage.rings.number_field x TESTS:: - sage: for A in (RR, CC, QQbar): + sage: fields = [RR, CC] + sage: fields.append(QQbar) # optional - sage.rings.number_field + sage: for A in fields: ....: g = A._gcd_univariate_polynomial ....: R. = A[] ....: z = R.zero() @@ -330,7 +332,9 @@ def _xgcd_univariate_polynomial(self, a, b): TESTS:: - sage: for A in (RR, CC, QQbar): + sage: fields = [RR, CC] + sage: fields.append(QQbar) # optional - sage.rings.number_field + sage: for A in fields: ....: g = A._xgcd_univariate_polynomial ....: R. = A[] ....: z, h = R(0), R(1/2) @@ -388,9 +392,9 @@ def is_perfect(self): sage: QQ.is_perfect() True - sage: GF(2).is_perfect() + sage: GF(2).is_perfect() # optional - sage.rings.finite_rings True - sage: FunctionField(GF(2), 'x').is_perfect() + sage: FunctionField(GF(2), 'x').is_perfect() # optional - sage.rings.finite_rings False """ @@ -464,11 +468,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)) - sage: x.squarefree_decomposition() + sage: x = polygen(GF(3)) # optional - sage.rings.finite_rings + sage: x.squarefree_decomposition() # optional - sage.rings.finite_rings x - sage: f = QQbar['x'](1) - sage: f.squarefree_decomposition() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.squarefree_decomposition() # optional - sage.rings.number_field 1 """ from sage.structure.factorization import Factorization @@ -525,10 +529,10 @@ 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: 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 (3*a^2 + 2*a + 1) + O(5^7) """ return self.free_module(*args, **kwds) @@ -601,12 +605,13 @@ def gcd(self,other): EXAMPLES:: - sage: K = GF(5) - sage: K(2).gcd(K(1)) + sage: K = GF(5) # optional - sage.rings.finite_rings + sage: K(2).gcd(K(1)) # optional - sage.rings.finite_rings 1 - sage: K(0).gcd(K(0)) + sage: K(0).gcd(K(0)) # optional - sage.rings.finite_rings 0 - sage: all(x.gcd(y) == (0 if x == 0 and y == 0 else 1) for x in K for y in K) + sage: all(x.gcd(y) == (0 if x == 0 and y == 0 else 1) # optional - sage.rings.finite_rings + ....: for x in K for y in K) True For field of characteristic zero, the gcd of integers is considered @@ -658,9 +663,9 @@ def lcm(self, other): EXAMPLES:: - sage: GF(2)(1).lcm(GF(2)(0)) + sage: GF(2)(1).lcm(GF(2)(0)) # optional - sage.rings.finite_rings 0 - sage: GF(2)(1).lcm(GF(2)(1)) + sage: GF(2)(1).lcm(GF(2)(1)) # optional - sage.rings.finite_rings 1 For field of characteristic zero, the lcm of integers is considered @@ -721,14 +726,14 @@ def xgcd(self, other): EXAMPLES:: - sage: K = GF(5) - sage: K(2).xgcd(K(1)) + sage: K = GF(5) # optional - sage.rings.finite_rings + sage: K(2).xgcd(K(1)) # optional - sage.rings.finite_rings (1, 3, 0) - sage: K(0).xgcd(K(4)) + sage: K(0).xgcd(K(4)) # optional - sage.rings.finite_rings (1, 0, 4) - sage: K(1).xgcd(K(1)) + sage: K(1).xgcd(K(1)) # optional - sage.rings.finite_rings (1, 1, 0) - sage: GF(5)(0).xgcd(GF(5)(0)) + sage: GF(5)(0).xgcd(GF(5)(0)) # optional - sage.rings.finite_rings (0, 0, 0) The xgcd of non-zero floating point numbers will be a triple of @@ -772,8 +777,8 @@ def factor(self): EXAMPLES:: - sage: x = GF(7)(5) - sage: x.factor() + sage: x = GF(7)(5) # optional - sage.rings.finite_rings + sage: x.factor() # optional - sage.rings.finite_rings 5 sage: RR(0).factor() Traceback (most recent call last): @@ -791,7 +796,8 @@ def inverse_of_unit(self): EXAMPLES:: - sage: NumberField(x^7+2,'a')(2).inverse_of_unit() + sage: x = polygen(ZZ, 'x') + sage: NumberField(x^7+2, 'a')(2).inverse_of_unit() # optional - sage.rings.number_field 1/2 Trying to invert the zero element typically raises a diff --git a/src/sage/categories/filtered_hopf_algebras_with_basis.py b/src/sage/categories/filtered_hopf_algebras_with_basis.py index 08888c78313..ca2dc9ac513 100644 --- a/src/sage/categories/filtered_hopf_algebras_with_basis.py +++ b/src/sage/categories/filtered_hopf_algebras_with_basis.py @@ -88,14 +88,14 @@ def antipode_on_basis(self, index): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() - sage: H.monomial(0).antipode() # indirect doctest + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.combinat + sage: H.monomial(0).antipode() # indirect doctest # optional - sage.combinat P0 - sage: H.monomial(1).antipode() # indirect doctest + sage: H.monomial(1).antipode() # indirect doctest # optional - sage.combinat -P1 - sage: H.monomial(2).antipode() # indirect doctest + sage: H.monomial(2).antipode() # indirect doctest # optional - sage.combinat P2 - sage: H.monomial(3).antipode() # indirect doctest + sage: H.monomial(3).antipode() # indirect doctest # optional - sage.combinat -P3 """ if self.monomial(index) == self.one(): @@ -116,15 +116,15 @@ def antipode(self, elem): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() - sage: H.antipode(H.monomial(14)) + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.combinat + sage: H.antipode(H.monomial(14)) # optional - sage.combinat P14 - sage: H.monomial(0).antipode() + sage: H.monomial(0).antipode() # optional - sage.combinat P0 - sage: H.monomial(2).antipode() + sage: H.monomial(2).antipode() # optional - sage.combinat P2 - sage: (2*H.monomial(1) + 3*H.monomial(4)).antipode() + sage: (2*H.monomial(1) + 3*H.monomial(4)).antipode() # optional - sage.combinat -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 336c1c326c8..7a9b2684f79 100644 --- a/src/sage/categories/filtered_modules_with_basis.py +++ b/src/sage/categories/filtered_modules_with_basis.py @@ -200,8 +200,10 @@ def homogeneous_component_basis(self, d): sage: A = GradedModulesWithBasis(ZZ).example() sage: A.homogeneous_component_basis(4) - Lazy family (Term map from Partitions 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} + Lazy family (Term map + from Partitions + 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: cat = GradedModulesWithBasis(ZZ) sage: C = CombinatorialFreeModule(ZZ, ['a', 'b'], category=cat) @@ -316,12 +318,12 @@ def to_graded_conversion(self): EXAMPLES:: - sage: A = Modules(QQ).WithBasis().Filtered().example() - sage: p = -2 * A.an_element(); p + sage: A = Modules(QQ).WithBasis().Filtered().example() # optional - sage.combinat + sage: p = -2 * A.an_element(); p # optional - sage.combinat -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.to_graded_conversion()(p); q + sage: q = A.to_graded_conversion()(p); q # optional - sage.combinat -4*Bbar[[]] - 4*Bbar[[1]] - 6*Bbar[[2]] - sage: q.parent() is A.graded_algebra() + sage: q.parent() is A.graded_algebra() # optional - sage.combinat True """ base_one = self.base_ring().one() @@ -344,14 +346,14 @@ def from_graded_conversion(self): EXAMPLES:: - sage: A = Modules(QQ).WithBasis().Filtered().example() - sage: p = -2 * A.an_element(); p + sage: A = Modules(QQ).WithBasis().Filtered().example() # optional - sage.combinat + sage: p = -2 * A.an_element(); p # optional - sage.combinat -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.to_graded_conversion()(p); q + sage: q = A.to_graded_conversion()(p); q # optional - sage.combinat -4*Bbar[[]] - 4*Bbar[[1]] - 6*Bbar[[2]] - sage: A.from_graded_conversion()(q) == p + sage: A.from_graded_conversion()(q) == p # optional - sage.combinat True - sage: q.parent() is A.graded_algebra() + sage: q.parent() is A.graded_algebra() # optional - sage.combinat True """ base_one = self.base_ring().one() @@ -376,14 +378,14 @@ def projection(self, i): EXAMPLES:: - sage: A = Modules(ZZ).WithBasis().Filtered().example() - sage: p = -2 * A.an_element(); p + sage: A = Modules(ZZ).WithBasis().Filtered().example() # optional - sage.combinat + sage: p = -2 * A.an_element(); p # optional - sage.combinat -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.projection(2)(p); q + sage: q = A.projection(2)(p); q # optional - sage.combinat -6*Bbar[[2]] - sage: q.parent() is A.graded_algebra() + sage: q.parent() is A.graded_algebra() # optional - sage.combinat True - sage: A.projection(3)(p) + sage: A.projection(3)(p) # optional - sage.combinat 0 """ base_zero = self.base_ring().zero() @@ -437,50 +439,55 @@ 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 + sage: A = Modules(QQ).WithBasis().Filtered().example(); A # optional - sage.combinat An example of a filtered module with basis: the free module on partitions over Rational Field - sage: M = A.indices(); M + sage: M = A.indices(); M # optional - sage.combinat Partitions - sage: p1, p2, p21, p321 = [A.basis()[Partition(i)] for i in [[1], [2], [2,1], [3,2,1]]] + sage: p1, p2, p21, p321 = [A.basis()[Partition(i)] # optional - sage.combinat + ....: for i in [[1], [2], [2,1], [3,2,1]]] Let us define a map from ``A`` to itself which acts on the basis by sending every partition `\lambda` to the sum of the conjugates of all partitions `\mu` for which `\lambda / \mu` is a horizontal strip:: - sage: def map_on_basis(lam): - ....: return A.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = A.module_morphism(on_basis=map_on_basis, + sage: def map_on_basis(lam): # optional - sage.combinat + ....: 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 ....: codomain=A) - sage: f(p1) + sage: f(p1) # optional - sage.combinat P[] + P[1] - sage: f(p2) + sage: f(p2) # optional - sage.combinat P[] + P[1] + P[1, 1] - sage: f(p21) + sage: f(p21) # optional - sage.combinat P[1] + P[1, 1] + P[2] + P[2, 1] - sage: f(p21 - p1) + sage: f(p21 - p1) # optional - sage.combinat -P[] + P[1, 1] + P[2] + P[2, 1] - sage: f(p321) + sage: f(p321) # optional - sage.combinat 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 + sage: grA = A.graded_algebra(); grA # optional - sage.combinat 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) for i in [p1, p2, p21, p321]] - sage: pp2 + 4 * pp21 + sage: pp1, pp2, pp21, pp321 = [A.to_graded_conversion()(i) # optional - sage.combinat + ....: for i in [p1, p2, p21, p321]] + sage: pp2 + 4 * pp21 # optional - sage.combinat Bbar[[2]] + 4*Bbar[[2, 1]] - 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) + sage: grf = A.induced_graded_map(A, f); grf # optional - sage.combinat + 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 Bbar[[1]] - sage: grf(pp2 + 4 * pp21) + sage: grf(pp2 + 4 * pp21) # optional - sage.combinat Bbar[[1, 1]] + 4*Bbar[[2, 1]] **Example 2.** @@ -490,45 +497,48 @@ 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() - sage: def map_on_basis(lam): # redefining map_on_basis - ....: return h.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = A.module_morphism(on_basis=map_on_basis, + sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat + sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + ....: 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 ....: codomain=h) # redefining f - sage: f(p1) + sage: f(p1) # optional - sage.combinat h[] + h[1] - sage: f(p2) + sage: f(p2) # optional - sage.combinat h[] + h[1] + h[1, 1] - sage: f(A.zero()) + sage: f(A.zero()) # optional - sage.combinat 0 - sage: f(p2 - 3*p1) + sage: f(p2 - 3*p1) # optional - sage.combinat -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 + sage: grh = h.graded_algebra(); grh is h # optional - sage.combinat True - sage: grf = A.induced_graded_map(h, f); grf + sage: grf = A.induced_graded_map(h, f); grf # optional - sage.combinat 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) + sage: grf(pp1) # optional - sage.combinat h[1] - sage: grf(pp2) + sage: grf(pp2) # optional - sage.combinat h[1, 1] - sage: grf(pp321) + sage: grf(pp321) # optional - sage.combinat h[3, 2, 1] - sage: grf(pp2 - 3*pp1) + sage: grf(pp2 - 3*pp1) # optional - sage.combinat -3*h[1] + h[1, 1] - sage: grf(pp21) + sage: grf(pp21) # optional - sage.combinat h[2, 1] - sage: grf(grA.zero()) + sage: grf(grA.zero()) # optional - sage.combinat 0 **Example 3.** @@ -537,42 +547,45 @@ 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 - ....: return A.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = h.module_morphism(on_basis=map_on_basis, + sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + ....: 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 ....: codomain=A) # redefining f - sage: f(h[1]) + sage: f(h[1]) # optional - sage.combinat P[] + P[1] - sage: f(h[2]) + sage: f(h[2]) # optional - sage.combinat P[] + P[1] + P[1, 1] - sage: f(h[1, 1]) + sage: f(h[1, 1]) # optional - sage.combinat P[1] + P[2] - sage: f(h[2, 2]) + sage: f(h[2, 2]) # optional - sage.combinat P[1, 1] + P[2, 1] + P[2, 2] - sage: f(h[3, 2, 1]) + sage: f(h[3, 2, 1]) # optional - sage.combinat 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()) + sage: f(h.one()) # optional - sage.combinat P[] - sage: grf = h.induced_graded_map(A, f); grf + sage: grf = h.induced_graded_map(A, f); grf # optional - sage.combinat 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]) + sage: grf(h[1]) # optional - sage.combinat Bbar[[1]] - sage: grf(h[2]) + sage: grf(h[2]) # optional - sage.combinat Bbar[[1, 1]] - sage: grf(h[1, 1]) + sage: grf(h[1, 1]) # optional - sage.combinat Bbar[[2]] - sage: grf(h[2, 2]) + sage: grf(h[2, 2]) # optional - sage.combinat Bbar[[2, 2]] - sage: grf(h[3, 2, 1]) + sage: grf(h[3, 2, 1]) # optional - sage.combinat Bbar[[3, 2, 1]] - sage: grf(h.one()) + sage: grf(h.one()) # optional - sage.combinat Bbar[[]] **Example 4.** @@ -580,33 +593,36 @@ 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 - ....: return h.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = h.module_morphism(on_basis=map_on_basis, + sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + ....: 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 ....: codomain=h) # redefining f - sage: f(h[1]) + sage: f(h[1]) # optional - sage.combinat h[] + h[1] - sage: f(h[2]) + sage: f(h[2]) # optional - sage.combinat h[] + h[1] + h[1, 1] - sage: f(h[1, 1]) + sage: f(h[1, 1]) # optional - sage.combinat h[1] + h[2] - sage: f(h[2, 1]) + sage: f(h[2, 1]) # optional - sage.combinat h[1] + h[1, 1] + h[2] + h[2, 1] - sage: f(h.one()) + sage: f(h.one()) # optional - sage.combinat h[] - 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]) + sage: grf = h.induced_graded_map(h, f); grf # optional - sage.combinat + Generic endomorphism of + Symmetric Functions over Rational Field in the homogeneous basis + sage: grf(h[1]) # optional - sage.combinat h[1] - sage: grf(h[2]) + sage: grf(h[2]) # optional - sage.combinat h[1, 1] - sage: grf(h[1, 1]) + sage: grf(h[1, 1]) # optional - sage.combinat h[2] - sage: grf(h[2, 1]) + sage: grf(h[2, 1]) # optional - sage.combinat h[2, 1] - sage: grf(h.one()) + sage: grf(h.one()) # optional - sage.combinat h[] """ grA = self.graded_algebra() @@ -643,26 +659,26 @@ def is_homogeneous(self): EXAMPLES:: - 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() + 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 True - sage: (x - y).is_homogeneous() + sage: (x - y).is_homogeneous() # optional - sage.combinat False - sage: (x+2*z).is_homogeneous() + sage: (x+2*z).is_homogeneous() # optional - sage.combinat True Here is an example with a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: (x, y) = (S[2], S[3]) - sage: (3*x).is_homogeneous() + 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 True - sage: (x^3 - y^2).is_homogeneous() + sage: (x^3 - y^2).is_homogeneous() # optional - sage.combinat True - sage: ((x + y)^2).is_homogeneous() + sage: ((x + y)^2).is_homogeneous() # optional - sage.combinat False Let us now test a filtered algebra (but remember that the @@ -701,10 +717,10 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: A = GradedModulesWithBasis(QQ).example() - sage: A.degree_on_basis(Partition((2,1))) + sage: A = GradedModulesWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.degree_on_basis(Partition((2,1))) # optional - sage.combinat sage.modules 3 - sage: A.degree_on_basis(Partition((4,2,1,1,1,1))) + sage: A.degree_on_basis(Partition((4,2,1,1,1,1))) # optional - sage.combinat sage.modules 10 """ @@ -722,28 +738,28 @@ def homogeneous_degree(self): EXAMPLES:: - 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() + 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 6 - sage: (x + 2*z).degree() + sage: (x + 2*z).degree() # optional - sage.combinat sage.modules 6 - sage: (y - x).degree() + sage: (y - x).degree() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous An example in a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: (x, y) = (S[2], S[3]) - sage: x.homogeneous_degree() + 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 2 - sage: (x^3 + 4*y^2).homogeneous_degree() + sage: (x^3 + 4*y^2).homogeneous_degree() # optional - sage.combinat sage.modules 6 - sage: ((1 + x)^3).homogeneous_degree() + sage: ((1 + x)^3).homogeneous_degree() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous @@ -765,8 +781,8 @@ def homogeneous_degree(self): TESTS:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S.zero().degree() + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat sage.modules + sage: S.zero().degree() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: the zero element does not have a well-defined degree @@ -793,28 +809,28 @@ def maximal_degree(self): EXAMPLES:: - 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() + 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 6 - sage: (x + 2*z).maximal_degree() + sage: (x + 2*z).maximal_degree() # optional - sage.combinat 6 - sage: (y - x).maximal_degree() + sage: (y - x).maximal_degree() # optional - sage.combinat 9 - sage: (3*z).maximal_degree() + sage: (3*z).maximal_degree() # optional - sage.combinat 6 Now, we test this on a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: (x, y) = (S[2], S[3]) - sage: x.maximal_degree() + 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 2 - sage: (x^3 + 4*y^2).maximal_degree() + sage: (x^3 + 4*y^2).maximal_degree() # optional - sage.combinat 6 - sage: ((1 + x)^3).maximal_degree() + sage: ((1 + x)^3).maximal_degree() # optional - sage.combinat 6 Let us now test a filtered algebra:: @@ -836,8 +852,8 @@ def maximal_degree(self): TESTS:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S.zero().degree() + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: S.zero().degree() # optional - sage.combinat Traceback (most recent call last): ... ValueError: the zero element does not have a well-defined degree @@ -998,16 +1014,16 @@ def degree_on_basis(self, m): EXAMPLES:: - 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()] + 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 [x, y, x*y - y*z] - sage: S.degree_on_basis(0) + sage: S.degree_on_basis(0) # optional - sage.combinat sage.modules 1 - sage: S.degree_on_basis(1) + sage: S.degree_on_basis(1) # optional - sage.combinat sage.modules 1 - sage: S.degree_on_basis(2) + sage: S.degree_on_basis(2) # optional - sage.combinat sage.modules 2 """ return self.basis()[m].lift().degree() @@ -1019,29 +1035,29 @@ def degree(self): EXAMPLES:: - 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()] + 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 [x, y, x*y - y*z] - sage: B[0].degree() + sage: B[0].degree() # optional - sage.combinat sage.modules 1 - sage: B[1].degree() + sage: B[1].degree() # optional - sage.combinat sage.modules 1 - sage: (B[0] + 3*B[1]).degree() + sage: (B[0] + 3*B[1]).degree() # optional - sage.combinat sage.modules 1 The degree of inhomogeneous elements is not defined (following the behavior of the exterior algebra):: - sage: (B[0] + B[2]).degree() + sage: (B[0] + B[2]).degree() # optional - sage.combinat 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() + sage: (B[0] + B[2]).maximal_degree() # optional - sage.combinat sage.modules 2 """ return self.lift().degree() @@ -1059,14 +1075,14 @@ def maximal_degree(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: F = E.submodule([x + 1, x*y - 1]) - sage: B = F.basis() - sage: [B[0].lift(), B[1].lift()] + 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 [-x*y + 1, x*y + x] - sage: B[0].maximal_degree() + sage: B[0].maximal_degree() # optional - sage.combinat sage.modules 2 - sage: B[1].maximal_degree() + sage: B[1].maximal_degree() # optional - sage.combinat sage.modules 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 8648f89dbc4..f4ab8a943ce 100644 --- a/src/sage/categories/finite_complex_reflection_groups.py +++ b/src/sage/categories/finite_complex_reflection_groups.py @@ -56,7 +56,7 @@ class FiniteComplexReflectionGroups(CategoryWithAxiom): sage: W = ComplexReflectionGroups().Finite().example(); W # optional - gap3 Reducible real reflection group of rank 4 and type A2 x B2 - sage: W.reflections() # optional - gap3 + sage: W.reflections() # optional - gap3 Finite family {1: (1,8)(2,5)(9,12), 2: (1,5)(2,9)(8,12), 3: (3,10)(4,7)(11,14), 4: (3,6)(4,11)(10,13), 5: (1,9)(2,8)(5,12), 6: (4,14)(6,13)(7,11), @@ -64,7 +64,7 @@ class FiniteComplexReflectionGroups(CategoryWithAxiom): ``W`` is in the category of complex reflection groups:: - sage: W in ComplexReflectionGroups().Finite() # optional - gap3 + sage: W in ComplexReflectionGroups().Finite() # optional - gap3 True """ def example(self): @@ -104,14 +104,14 @@ def WellGenerated(self): Here is an example of a finite well-generated complex reflection group:: - sage: W = C.example(); W # optional - gap3 + sage: W = C.example(); W # optional - gap3 Reducible complex reflection group of rank 4 and type A2 x G(3,1,2) All finite Coxeter groups are well generated:: sage: CoxeterGroups().Finite().is_subcategory(C) True - sage: SymmetricGroup(3) in C + sage: SymmetricGroup(3) in C # optional - sage.groups True .. NOTE:: @@ -124,8 +124,9 @@ def WellGenerated(self): TESTS:: - sage: TestSuite(W).run() # optional - gap3 - sage: TestSuite(ComplexReflectionGroups().Finite().WellGenerated()).run() # optional - gap3 + sage: TestSuite(W).run() # optional - gap3 + sage: C = ComplexReflectionGroups().Finite().WellGenerated() + sage: TestSuite(C).run() # optional - gap3 sage: CoxeterGroups().Finite().WellGenerated.__module__ 'sage.categories.finite_complex_reflection_groups' @@ -148,12 +149,12 @@ def degrees(self): EXAMPLES:: - sage: W = ColoredPermutations(1,4) - sage: W.degrees() + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.degrees() # optional - sage.combinat sage.groups (2, 3, 4) - sage: W = ColoredPermutations(3,3) - sage: W.degrees() + sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups + sage: W.degrees() # optional - sage.combinat sage.groups (3, 6, 9) sage: W = ReflectionGroup(31) # optional - gap3 @@ -170,12 +171,12 @@ def codegrees(self): EXAMPLES:: - sage: W = ColoredPermutations(1,4) - sage: W.codegrees() + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.codegrees() # optional - sage.combinat sage.groups (2, 1, 0) - sage: W = ColoredPermutations(3,3) - sage: W.codegrees() + sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups + sage: W.codegrees() # optional - sage.combinat sage.groups (6, 3, 0) sage: W = ReflectionGroup(31) # optional - gap3 @@ -198,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) - sage: W._test_degrees() + sage: W = SymmetricGroup(5) # optional - sage.groups + sage: W._test_degrees() # optional - sage.groups We now break the implementation of W.degrees and check that this is caught:: - sage: W.degrees = lambda: (1/1,5) - sage: W._test_degrees() + sage: W.degrees = lambda: (1/1,5) # optional - sage.groups + sage: W._test_degrees() # optional - sage.groups Traceback (most recent call last): ... AssertionError: the degrees should be integers - sage: W.degrees = lambda: (1,2,3) - sage: W._test_degrees() + sage: W.degrees = lambda: (1,2,3) # optional - sage.groups + sage: W._test_degrees() # optional - 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 - sage: W._test_degrees() + sage: del W.degrees # optional - sage.groups + sage: W._test_degrees() # optional - sage.groups See the documentation for :class:`TestSuite` for more information. """ @@ -253,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) - sage: W._test_codegrees() + sage: W = SymmetricGroup(5) # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups We now break the implementation of W.degrees and check that this is caught:: - sage: W.codegrees = lambda: (1/1,5) - sage: W._test_codegrees() + sage: W.codegrees = lambda: (1/1,5) # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups Traceback (most recent call last): ... AssertionError: the codegrees should be integers - sage: W.codegrees = lambda: (2,1,-1) - sage: W._test_codegrees() + sage: W.codegrees = lambda: (2,1,-1) # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups Traceback (most recent call last): ... AssertionError: the codegrees should be nonnegative We restore W to its normal state:: - sage: del W.codegrees - sage: W._test_codegrees() + sage: del W.codegrees # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups See the documentation for :class:`TestSuite` for more information. """ @@ -310,14 +311,14 @@ def number_of_reflection_hyperplanes(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.number_of_reflection_hyperplanes() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(2,3) - sage: W.number_of_reflection_hyperplanes() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups 9 - sage: W = ColoredPermutations(4,3) - sage: W.number_of_reflection_hyperplanes() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups 15 sage: W = ReflectionGroup((4,2,3)) # optional - gap3 sage: W.number_of_reflection_hyperplanes() # optional - gap3 @@ -341,20 +342,21 @@ def number_of_reflections(self): EXAMPLES:: - sage: [SymmetricGroup(i).number_of_reflections() for i in range(int(8))] + sage: [SymmetricGroup(i).number_of_reflections() # optional - sage.groups + ....: for i in range(int(8))] [0, 0, 1, 3, 6, 10, 15, 21] - sage: W = ColoredPermutations(1,3) - sage: W.number_of_reflections() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(2,3) - sage: W.number_of_reflections() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections() # optional - sage.combinat sage.groups 9 - sage: W = ColoredPermutations(4,3) - sage: W.number_of_reflections() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections() # optional - sage.combinat sage.groups 21 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.number_of_reflections() # optional - gap3 + 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 15 """ from sage.rings.integer_ring import ZZ @@ -375,17 +377,17 @@ def rank(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.rank() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.rank() # optional - sage.combinat sage.groups 2 - sage: W = ColoredPermutations(2,3) - sage: W.rank() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.rank() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(4,3) - sage: W.rank() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.rank() # optional - sage.combinat sage.groups 3 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.rank() # optional - gap3 + sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups + sage: W.rank() # optional - gap3 # optional - sage.combinat sage.groups 3 """ return len(self.degrees()) @@ -399,17 +401,17 @@ def cardinality(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.cardinality() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - sage.combinat sage.groups 6 - sage: W = ColoredPermutations(2,3) - sage: W.cardinality() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - sage.combinat sage.groups 48 - sage: W = ColoredPermutations(4,3) - sage: W.cardinality() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - sage.combinat sage.groups 384 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.cardinality() # optional - gap3 + sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - gap3 # optional - sage.combinat sage.groups 192 """ from sage.rings.integer_ring import ZZ @@ -437,20 +439,20 @@ def is_well_generated(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.is_well_generated() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.is_well_generated() # optional - sage.combinat sage.groups True - sage: W = ColoredPermutations(4,3) - sage: W.is_well_generated() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.is_well_generated() # optional - sage.combinat sage.groups True - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.is_well_generated() # optional - gap3 + 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 False - sage: W = ReflectionGroup((4,4,3)) # optional - gap3 - sage: W.is_well_generated() # optional - gap3 + 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 True """ return self.number_of_simple_reflections() == self.rank() @@ -472,12 +474,12 @@ def is_real(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.is_real() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.is_real() # optional - sage.combinat sage.groups True - sage: W = ColoredPermutations(4,3) - sage: W.is_real() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.is_real() # optional - sage.combinat sage.groups False .. TODO:: @@ -501,24 +503,24 @@ def base_change_matrix(self): EXAMPLES:: - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [1 0] [0 1] - sage: W = ReflectionGroup(23) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup(23) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [1 0 0] [0 1 0] [0 0 1] - sage: W = ReflectionGroup((3,1,2)) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup((3,1,2)) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [1 0] [1 1] - sage: W = ReflectionGroup((4,2,2)) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup((4,2,2)) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [ 1 0] [E(4) 1] """ @@ -542,8 +544,8 @@ def to_matrix(self): [0 1], [ 0 -1], [ 1 1], [ 1 0], [-1 -1], [-1 0] ] - sage: W = ColoredPermutations(1,3) - sage: [t.to_matrix() for t in W] + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: [t.to_matrix() for t in W] # optional - 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] @@ -553,8 +555,8 @@ def to_matrix(self): A different representation is given by the colored permutations:: - sage: W = ColoredPermutations(3, 1) - sage: [t.to_matrix() for t in W] + sage: W = ColoredPermutations(3, 1) # optional - sage.combinat sage.groups + sage: [t.to_matrix() for t in W] # optional - sage.combinat sage.groups [[1], [zeta3], [-zeta3 - 1]] """ @@ -580,9 +582,9 @@ def character_value(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3); W + sage: W = ColoredPermutations(1,3); W # optional - sage.combinat sage.groups 1-colored permutations of size 3 - sage: [t.character_value() for t in W] + sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups [3, 1, 1, 0, 0, 1] Note that this could be a different (faithful) @@ -594,14 +596,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 + sage: W = ColoredPermutations(2,2); W # optional - sage.combinat sage.groups 2-colored permutations of size 2 - sage: [t.character_value() for t in W] + sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups [2, 0, 0, -2, 0, 0, 0, 0] - sage: W = ColoredPermutations(3,1); W + sage: W = ColoredPermutations(3,1); W # optional - sage.combinat sage.groups 3-colored permutations of size 1 - sage: [t.character_value() for t in W] + sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups [1, zeta3, -zeta3 - 1] """ return self.to_matrix().trace() @@ -622,20 +624,20 @@ def reflection_length(self, in_unitary_group=False): EXAMPLES:: - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 1, 2, 2] - sage: W = ReflectionGroup((2,1,2)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((2,1,2)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 1, 1, 2, 2, 2] - sage: W = ReflectionGroup((2,2,2)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((2,2,2)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 2] - sage: W = ReflectionGroup((3,1,2)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((3,1,2)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] """ W = self.parent() @@ -655,7 +657,8 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().Finite().Irreducible().example() # optional - gap3 + sage: C = ComplexReflectionGroups().Finite().Irreducible() + sage: C.example() # optional - gap3 Irreducible complex reflection group of rank 3 and type G(4,2,3) """ from sage.combinat.root_system.reflection_group_real import ReflectionGroup @@ -733,23 +736,26 @@ def absolute_order_ideal(self, gens=None, EXAMPLES:: - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted( w.reduced_word() for w in W.absolute_order_ideal() ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.absolute_order_ideal()) [[], [1], [1, 2], [1, 2, 1], [2]] - sage: sorted( w.reduced_word() for w in W.absolute_order_ideal(W.from_reduced_word([2,1])) ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.absolute_order_ideal(W.from_reduced_word([2,1]))) [[], [1], [1, 2, 1], [2], [2, 1]] - sage: sorted( w.reduced_word() for w in W.absolute_order_ideal(W.from_reduced_word([2])) ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.absolute_order_ideal(W.from_reduced_word([2]))) [[], [2]] - sage: W = CoxeterGroup(['A', 3]) - sage: len(list(W.absolute_order_ideal())) + sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: len(list(W.absolute_order_ideal())) # optional - sage.combinat sage.groups 14 - sage: W = CoxeterGroup(['A', 2]) - sage: for (w, l) in W.absolute_order_ideal(return_lengths=True): + 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 ....: print(w.reduced_word(), l) [1, 2] 2 [1, 2, 1] 1 @@ -793,9 +799,10 @@ def elements_below_coxeter_element(self, c=None): TESTS:: - sage: W = CoxeterGroup(['A', 3]) - sage: len(list(W.elements_below_coxeter_element())) - doctest:...: DeprecationWarning: The method elements_below_coxeter_element is deprecated. Please use absolute_order_ideal instead. + sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: len(list(W.elements_below_coxeter_element())) # optional - sage.combinat sage.groups + doctest:...: DeprecationWarning: The method elements_below_coxeter_element + is deprecated. Please use absolute_order_ideal instead. See https://github.com/sagemath/sage/issues/27924 for details. 14 """ @@ -835,23 +842,28 @@ def noncrossing_partition_lattice(self, c=None, L=None, EXAMPLES:: - sage: W = SymmetricGroup(4) - sage: W.noncrossing_partition_lattice() + sage: W = SymmetricGroup(4) # optional - sage.combinat sage.groups + sage: W.noncrossing_partition_lattice() # optional - sage.combinat sage.groups Finite lattice containing 14 elements - sage: W = WeylGroup(['G', 2]) - sage: W.noncrossing_partition_lattice() + sage: W = WeylGroup(['G', 2]) # optional - sage.combinat sage.groups + sage: W.noncrossing_partition_lattice() # optional - sage.combinat sage.groups Finite lattice containing 8 elements - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted( w.reduced_word() for w in W.noncrossing_partition_lattice() ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.noncrossing_partition_lattice()) [[], [1], [1, 2], [1, 2, 1], [2]] - sage: sorted( w.reduced_word() for w in W.noncrossing_partition_lattice(W.from_reduced_word([2,1])) ) # optional - gap3 + sage: c21 = W.from_reduced_word([2,1]) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.noncrossing_partition_lattice(c21)) [[], [1], [1, 2, 1], [2], [2, 1]] - sage: sorted( w.reduced_word() for w in W.noncrossing_partition_lattice(W.from_reduced_word([2])) ) # optional - gap3 + sage: c2 = W.from_reduced_word([2]) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.noncrossing_partition_lattice(c2)) [[], [2]] """ from sage.combinat.posets.posets import Poset @@ -899,8 +911,9 @@ def generalized_noncrossing_partitions(self, m, c=None, positive=False): sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: chains = W.generalized_noncrossing_partitions(2) # optional - gap3 sage: sorted([w.reduced_word() for w in chain] # optional - gap3 - ....: for chain in W.generalized_noncrossing_partitions(2)) + ....: for chain in chains) [[[], [], [1, 2]], [[], [1], [2]], [[], [1, 2], []], @@ -914,8 +927,10 @@ def generalized_noncrossing_partitions(self, m, c=None, positive=False): [[2], [], [1, 2, 1]], [[2], [1, 2, 1], []]] + sage: chains = W.generalized_noncrossing_partitions(2, # optional - gap3 + ....: positive=True) sage: sorted([w.reduced_word() for w in chain] # optional - gap3 - ....: for chain in W.generalized_noncrossing_partitions(2, positive=True)) + ....: for chain in chains) [[[], [1, 2], []], [[], [1, 2, 1], [1]], [[1], [2], []], @@ -987,14 +1002,14 @@ def absolute_poset(self, in_unitary_group=False): TESTS:: - sage: W1 = CoxeterGroup(['A',2]) - sage: W2 = WeylGroup(['A',2]) - sage: W3 = SymmetricGroup(3) - sage: W1.absolute_poset() + 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 Finite poset containing 6 elements - sage: W2.absolute_poset() + sage: W2.absolute_poset() # optional - sage.combinat sage.groups Finite poset containing 6 elements - sage: W3.absolute_poset() + sage: W3.absolute_poset() # optional - sage.combinat sage.groups Finite poset containing 6 elements """ return self.noncrossing_partition_lattice(L=tuple(self), in_unitary_group=in_unitary_group) @@ -1008,7 +1023,8 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().Finite().WellGenerated().example() # optional - gap3 + sage: C = ComplexReflectionGroups().Finite().WellGenerated() + sage: C.example() # optional - gap3 Reducible complex reflection group of rank 4 and type A2 x G(3,1,2) """ from sage.combinat.root_system.reflection_group_real import ReflectionGroup @@ -1062,12 +1078,15 @@ def coxeter_elements(self): EXAMPLES:: sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted(c.reduced_word() for c in W.coxeter_elements()) # optional - gap3 + sage: sorted(c.reduced_word() # optional - gap3 + ....: for c in W.coxeter_elements()) [[1, 2], [2, 1]] sage: W = ReflectionGroup((1,1,4)) # optional - gap3 - sage: sorted(c.reduced_word() for c in W.coxeter_elements()) # optional - gap3 - [[1, 2, 1, 3, 2], [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 1, 3, 2, 1], [3, 2, 1]] + sage: sorted(c.reduced_word() # optional - gap3 + ....: for c in W.coxeter_elements()) + [[1, 2, 1, 3, 2], [1, 2, 3], [1, 3, 2], + [2, 1, 3], [2, 1, 3, 2, 1], [3, 2, 1]] """ return self.coxeter_element().conjugacy_class() @@ -1084,7 +1103,8 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().Finite().WellGenerated().Irreducible().example() + sage: C = ComplexReflectionGroups().Finite().WellGenerated().Irreducible() + sage: C.example() # optional - sage.combinat sage.groups 4-colored permutations of size 3 """ from sage.combinat.colored_permutations import ColoredPermutations @@ -1109,12 +1129,12 @@ def coxeter_number(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.coxeter_number() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.coxeter_number() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(4,3) - sage: W.coxeter_number() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.coxeter_number() # optional - sage.combinat sage.groups 12 sage: W = ReflectionGroup((4,4,3)) # optional - gap3 @@ -1130,20 +1150,20 @@ def number_of_reflections_of_full_support(self): EXAMPLES:: - sage: W = Permutations(4) - sage: W.number_of_reflections_of_full_support() + sage: W = Permutations(4) # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 1 - sage: W = ColoredPermutations(1,4) - sage: W.number_of_reflections_of_full_support() + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 1 - sage: W = CoxeterGroup("B3") - sage: W.number_of_reflections_of_full_support() + sage: W = CoxeterGroup("B3") # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(3,3) - sage: W.number_of_reflections_of_full_support() + sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 3 """ n = self.rank() @@ -1175,18 +1195,18 @@ def rational_catalan_number(self, p, polynomial=False): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: [W.rational_catalan_number(p) for p in [5,7,8]] + 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 [7, 12, 15] - sage: W = ColoredPermutations(2,2) - sage: [W.rational_catalan_number(p) for p in [7,9,11]] + 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 [10, 15, 21] TESTS:: - sage: W = ColoredPermutations(1,4) - sage: W.rational_catalan_number(3, polynomial=True) + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.rational_catalan_number(3, polynomial=True) # optional - sage.combinat sage.groups q^6 + q^4 + q^3 + q^2 + 1 """ from sage.arith.misc import GCD as gcd @@ -1243,37 +1263,37 @@ def fuss_catalan_number(self, m, positive=False, EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + 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 [5, 12, 22] - sage: W = ColoredPermutations(1,4) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + 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 [14, 55, 140] - sage: W = ColoredPermutations(1,5) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + 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 [42, 273, 969] - sage: W = ColoredPermutations(2,2) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + 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 [6, 15, 28] - sage: W = ColoredPermutations(2,3) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + 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 [20, 84, 220] - sage: W = ColoredPermutations(2,4) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + 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 [70, 495, 1820] TESTS:: - sage: W = ColoredPermutations(2,4) - sage: W.fuss_catalan_number(2,positive=True) + sage: W = ColoredPermutations(2,4) # optional - sage.combinat sage.groups + sage: W.fuss_catalan_number(2, positive=True) # optional - sage.combinat sage.groups 330 - sage: W = ColoredPermutations(2,2) - sage: W.fuss_catalan_number(2,polynomial=True) + sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups + sage: W.fuss_catalan_number(2, polynomial=True) # optional - sage.combinat sage.groups q^16 + q^14 + 2*q^12 + 2*q^10 + 3*q^8 + 2*q^6 + 2*q^4 + q^2 + 1 """ @@ -1317,22 +1337,25 @@ def catalan_number(self, positive=False, polynomial=False): EXAMPLES:: - sage: [ColoredPermutations(1,n).catalan_number() for n in [3,4,5]] + sage: [ColoredPermutations(1,n).catalan_number() # optional - sage.combinat sage.groups + ....: for n in [3,4,5]] [5, 14, 42] - sage: [ColoredPermutations(2,n).catalan_number() for n in [3,4,5]] + sage: [ColoredPermutations(2,n).catalan_number() # optional - sage.combinat sage.groups + ....: for n in [3,4,5]] [20, 70, 252] - sage: [ReflectionGroup((2,2,n)).catalan_number() for n in [3,4,5]] # optional - gap3 + sage: [ReflectionGroup((2,2,n)).catalan_number() # optional - gap3 + ....: for n in [3,4,5]] [14, 50, 182] TESTS:: - sage: W = ColoredPermutations(3,6) - sage: W.catalan_number(positive=True) + sage: W = ColoredPermutations(3,6) # optional - sage.combinat sage.groups + sage: W.catalan_number(positive=True) # optional - sage.combinat sage.groups 462 - sage: W = ColoredPermutations(2,2) - sage: W.catalan_number(polynomial=True) + sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups + sage: W.catalan_number(polynomial=True) # optional - sage.combinat sage.groups 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 270341c2262..0ec68ca2b99 100644 --- a/src/sage/categories/finite_coxeter_groups.py +++ b/src/sage/categories/finite_coxeter_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 072df1f9c53..f920da8b877 100644 --- a/src/sage/categories/finite_crystals.py +++ b/src/sage/categories/finite_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - 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 542cf09d425..ec4a65b8db1 100644 --- a/src/sage/categories/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_algebras_with_basis.py @@ -90,29 +90,29 @@ def radical_basis(self): We construct the group algebra of the Klein Four-Group over the rationals:: - sage: A = KleinFourGroup().algebra(QQ) + sage: A = KleinFourGroup().algebra(QQ) # optional - sage.groups sage.modules This algebra belongs to the category of finite dimensional algebras over the rationals:: - sage: A in Algebras(QQ).FiniteDimensional().WithBasis() + sage: A in Algebras(QQ).FiniteDimensional().WithBasis() # optional - 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() + sage: A in Algebras(QQ).Semisimple() # optional - sage.groups sage.modules True - sage: A.radical_basis() + sage: A.radical_basis() # optional - sage.groups sage.modules () Let's work instead over a field of characteristic `2`:: - sage: A = KleinFourGroup().algebra(GF(2)) - sage: A in Algebras(GF(2)).Semisimple() + 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 False - sage: A.radical_basis() + sage: A.radical_basis() # optional - sage.groups sage.rings.finite_rings 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 +120,7 @@ def radical_basis(self): radical; alas, we currently need to wrap `A` to make it a proper :class:`ModulesWithBasis`:: - sage: class AnAlgebra(CombinatorialFreeModule): + sage: class AnAlgebra(CombinatorialFreeModule): # optional - sage.modules ....: def __init__(self, F): ....: R. = PolynomialRing(F) ....: I = R.ideal(x**F.characteristic()-F.one()) @@ -132,24 +132,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() + sage: AnAlgebra(GF(3)).radical_basis() # optional - sage.rings.finite_rings sage.modules (B[1] + 2*B[xbar^2], B[xbar] + 2*B[xbar^2]) - sage: AnAlgebra(GF(16,'a')).radical_basis() + sage: AnAlgebra(GF(16,'a')).radical_basis() # optional - sage.rings.finite_rings sage.modules (B[1] + B[xbar],) - sage: AnAlgebra(GF(49,'a')).radical_basis() + sage: AnAlgebra(GF(49,'a')).radical_basis() # optional - sage.rings.finite_rings sage.modules (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)) - sage: A.radical_basis() + 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 (() + (1,2)(3,4), (3,4) + (1,2)(3,4), (1,2) + (1,2)(3,4)) - sage: A = KleinFourGroup().algebra(QQ, category=Monoids()) - sage: A.radical_basis.__module__ + sage: A = KleinFourGroup().algebra(QQ, category=Monoids()) # optional - sage.groups sage.modules + sage: A.radical_basis.__module__ # optional - sage.groups sage.modules 'sage.categories.finite_dimensional_algebras_with_basis' - sage: A.radical_basis() + sage: A.radical_basis() # optional - sage.groups sage.modules () """ F = self.base_ring() @@ -292,10 +292,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() + sage: [ DescentAlgebra(QQ,n).B().semisimple_quotient().dimension() # optional - sage.combinat ....: for n in range(6) ] [1, 1, 2, 3, 5, 7] - sage: [Partitions(n).cardinality() for n in range(10)] + sage: [Partitions(n).cardinality() for n in range(10)] # optional - sage.combinat [1, 1, 2, 3, 5, 7, 11, 15, 22, 30] .. TODO:: @@ -365,7 +365,8 @@ def center(self): The center of a semisimple algebra is semisimple:: - sage: DihedralGroup(6).algebra(QQ).center() in Algebras(QQ).Semisimple() + sage: A = DihedralGroup(6).algebra(QQ) # optional - sage.groups sage.modules + sage: A.center() in Algebras(QQ).Semisimple() # optional - sage.groups sage.modules True .. TODO:: @@ -473,7 +474,7 @@ def orthogonal_idempotents_central_mod_radical(self): 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() + sage: A.orthogonal_idempotents_central_mod_radical() # optional - sage.rings.number_field (x, y) :: @@ -496,7 +497,8 @@ def orthogonal_idempotents_central_mod_radical(self): True sage: all(e*e == e for e in idempotents) True - sage: all(e*f == 0 and f*e == 0 for e in idempotents for f in idempotents if e != f) + 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:: @@ -645,8 +647,8 @@ def cartan_invariants_matrix(self): in characteristic zero, the Cartan invariants matrix is the identity:: - sage: A3 = SymmetricGroup(3).algebra(QQ) - sage: A3.cartan_invariants_matrix() + sage: A3 = SymmetricGroup(3).algebra(QQ) # optional - sage.groups sage.modules + sage: A3.cartan_invariants_matrix() # optional - sage.groups sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -655,7 +657,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() + sage: A.cartan_invariants_matrix() # optional - sage.modules sage.rings.number_field [1 2] [0 1] @@ -663,8 +665,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) - sage: A.cartan_invariants_matrix() + sage: A = Z12.algebra(QQ) # optional - sage.modules + sage: A.cartan_invariants_matrix() # optional - sage.modules [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] @@ -677,9 +679,9 @@ def cartan_invariants_matrix(self): With the algebra of the `0`-Hecke monoid:: - sage: from sage.monoids.hecke_monoid import HeckeMonoid - sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) - sage: A.cartan_invariants_matrix() + 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 [1 0 0 0 0 0 0 0] [0 2 1 0 1 1 0 0] [0 1 1 0 1 0 0 0] @@ -739,10 +741,10 @@ def isotypic_projective_modules(self, side='left'): 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 + sage: Q = A.isotypic_projective_modules(side="left"); Q # optional - sage.rings.number_field [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()] + sage: [[x.lift() for x in Qi.basis()] # optional - sage.rings.number_field ....: for Qi in Q] [[x], [y, a, b]] @@ -750,7 +752,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() + sage: sum([Qi.dimension() for Qi in Q]) == A.dimension() # optional - sage.rings.number_field True .. SEEALSO:: @@ -782,19 +784,19 @@ def peirce_summand(self, ei, ej): EXAMPLES:: sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example() - sage: idemp = A.orthogonal_idempotents_central_mod_radical() - sage: A.peirce_summand(idemp[0], idemp[1]) + 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 Free module generated by {0, 1} over Rational Field - sage: A.peirce_summand(idemp[1], idemp[0]) + sage: A.peirce_summand(idemp[1], idemp[0]) # optional - 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) - sage: e = A4.central_orthogonal_idempotents()[2] - sage: A4.peirce_summand(e, e) + 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 Free module generated by {0, 1, 2, 3} over Rational Field TESTS: @@ -802,11 +804,11 @@ 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 - sage: M = HeckeMonoid(SymmetricGroup(4)) - sage: A = M.algebra(QQ) - sage: Idms = A.orthogonal_idempotents_central_mod_radical() - sage: all(A.peirce_summand(e, e).retract(e) + 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 ....: in A.peirce_summand(e, e) for e in Idms) True """ @@ -863,14 +865,14 @@ def peirce_decomposition(self, idempotents=None, check=True): 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() + sage: A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups (x, y) - sage: decomposition = A.peirce_decomposition(); decomposition + sage: decomposition = A.peirce_decomposition(); decomposition # optional - sage.groups sage.modules sage.rings.number_field [[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()] + sage: [ [[x.lift() for x in decomposition[i][j].basis()] # optional - sage.groups sage.modules sage.rings.number_field ....: for j in range(2)] ....: for i in range(2)] [[[x], [a, b]], @@ -879,9 +881,9 @@ 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) - sage: decomposition = A.peirce_decomposition() # long time - sage: [[decomposition[i][j].dimension() # long time (4s) + 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 ....: for j in range(len(decomposition))] ....: for i in range(len(decomposition))] [[9, 0, 0, 0, 0], @@ -894,7 +896,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)] + sage: [p.standard_tableaux().cardinality() for p in Partitions(4)] # optional - sage.combinat [1, 3, 2, 3, 1] """ if idempotents is None: @@ -926,9 +928,9 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): sage: A.is_identity_decomposition_into_orthogonal_idempotents([A.one()]) True - sage: A.is_identity_decomposition_into_orthogonal_idempotents([x,y]) + sage: A.is_identity_decomposition_into_orthogonal_idempotents([x, y]) True - sage: A.is_identity_decomposition_into_orthogonal_idempotents([x+a, y-a]) + sage: A.is_identity_decomposition_into_orthogonal_idempotents([x + a, y - a]) True Here the idempotents do not sum up to `1`:: @@ -938,15 +940,15 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): 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]) False With the algebra of the `0`-Hecke monoid:: - 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) + 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 True Here are some more counterexamples: @@ -971,40 +973,40 @@ 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() - sage: a, b = y, 1-y - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, b)) + 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 False For comparison:: - 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)) + 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 True - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, A.zero(), b)) + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, A.zero(), b)) # optional - sage.libs.pari True - 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)) + 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 True 2. Some idempotents summing to 1 but not orthogonal:: - sage: R. = PolynomialRing(GF(2)) - sage: A = PQAlgebra(GF(2), x) - sage: a = A.one() - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,)) + 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 True - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, a, a)) + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, a, a)) # optional - sage.rings.finite_rings False 3. Some orthogonal idempotents not summing to the identity:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,a)) + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,a)) # optional - sage.rings.finite_rings False - sage: A.is_identity_decomposition_into_orthogonal_idempotents(()) + sage: A.is_identity_decomposition_into_orthogonal_idempotents(()) # optional - sage.rings.finite_rings False """ return (self.sum(l) == self.one() @@ -1019,11 +1021,11 @@ def is_commutative(self): EXAMPLES:: - sage: S4 = SymmetricGroupAlgebra(QQ, 4) - sage: S4.is_commutative() + sage: S4 = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S4.is_commutative() # optional - sage.groups sage.modules False - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S2.is_commutative() + sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules + sage: S2.is_commutative() # optional - sage.groups sage.modules True """ B = list(self.basis()) @@ -1047,23 +1049,23 @@ def to_matrix(self, base_ring=None, action=operator.mul, side='left'): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) - sage: a = QS3([2,1,3]) - sage: a.to_matrix(side='left') + 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 [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') + sage: a.to_matrix(side='right') # optional - sage.groups sage.modules [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") + sage: a.to_matrix(base_ring=RDF, side="left") # optional - sage.groups sage.modules [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] @@ -1100,47 +1102,47 @@ def __invert__(self): EXAMPLES:: - 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 + 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 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 + sage: a * b # optional - sage.groups sage.modules [1, 2, 3] - sage: ~b == a + sage: ~b == a # optional - sage.groups sage.modules True - sage: a = 3 * QS3.one() - sage: b = ~a - sage: b * a == QS3.one() + 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 True - sage: b == 1/3 * QS3.one() + sage: b == 1/3 * QS3.one() # optional - sage.groups sage.modules True - sage: ~b == a + sage: ~b == a # optional - sage.groups sage.modules True sage: R. = QQ[] - sage: RS3 = SymmetricGroupAlgebra(R, 3) - sage: a = RS3(P([1,2,3])) - RS3(P([1,3,2])) + RS3(P([2,1,3])); ~a + 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 -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])) - sage: ~c + 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 Traceback (most recent call last): ... ValueError: cannot invert self (= 2*[1, 2, 3] + [1, 3, 2] + [2, 1, 3]) - 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 + 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 Traceback (most recent call last): ... ValueError: cannot invert self (= 3*[1, 2, 3] + [1, 3, 2] + [2, 1, 3]) - sage: x = 2 * ZS3.one() - sage: ~x + sage: x = 2 * ZS3.one() # optional - sage.groups sage.modules + sage: ~x # optional - sage.groups sage.modules Traceback (most recent call last): ... ValueError: cannot invert self (= 2*[1, 2, 3]) @@ -1149,9 +1151,9 @@ def __invert__(self): An algebra that does not define ``one_basis()``:: - sage: I = DescentAlgebra(QQ, 3).I() - sage: a = 3 * I.one() - sage: ~a == 1/3 * I.one() + 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 True """ alg = self.parent() @@ -1239,8 +1241,8 @@ def _test_cellular(self, **options): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S._test_cellular() + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: S._test_cellular() # optional - sage.combinat sage.modules """ tester = self._tester(**options) cell_basis = self.cellular_basis() @@ -1273,8 +1275,8 @@ def cell_poset(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: S.cell_poset() + sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S.cell_poset() # optional - sage.groups sage.modules Finite poset containing 5 elements """ @@ -1288,8 +1290,8 @@ def cell_module_indices(self, mu): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S.cell_module_indices([2,1]) + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: S.cell_module_indices([2,1]) # optional - sage.groups sage.modules Standard tableaux of shape [2, 1] """ @@ -1301,8 +1303,8 @@ def _to_cellular_element(self, i): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S._to_cellular_element # no implementation currently uses this + 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 NotImplemented """ @@ -1314,13 +1316,12 @@ def _from_cellular_index(self, x): EXAMPLES:: - 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] + 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 + 1/4*[1, 3, 2] - 1/4*[2, 3, 1] + 1/4*[3, 1, 2] - 1/4*[3, 2, 1] """ def cellular_involution(self, x): @@ -1329,8 +1330,8 @@ def cellular_involution(self, x): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: for b in S.basis(): b, S.cellular_involution(b) + 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 ([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]) @@ -1356,8 +1357,8 @@ def cells(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: dict(S.cells()) + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: dict(S.cells()) # optional - 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]} @@ -1371,8 +1372,8 @@ def cellular_basis(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S.cellular_basis() + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: S.cellular_basis() # optional - sage.groups sage.modules Cellular basis of Symmetric group algebra of order 3 over Rational Field """ @@ -1385,8 +1386,8 @@ def cell_module(self, mu, **kwds): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S.cell_module(Partition([2,1])) + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: S.cell_module(Partition([2,1])) # optional - 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 """ @@ -1404,8 +1405,8 @@ def simple_module_parameterization(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: S.simple_module_parameterization() + sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S.simple_module_parameterization() # optional - 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() @@ -1418,12 +1419,12 @@ def cellular_involution(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: elt = S([3,1,2,4]) - sage: ci = elt.cellular_involution(); ci + 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 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() + sage: ci.cellular_involution() # optional - sage.groups sage.modules [3, 1, 2, 4] """ return self.parent().cellular_involution(self) @@ -1455,10 +1456,10 @@ def cell_poset(self): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: T = S2.tensor(S3) - sage: T.cell_poset() + 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 Finite poset containing 6 elements """ ret = self._sets[0].cell_poset() @@ -1475,10 +1476,10 @@ def cell_module_indices(self, mu): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: T = S2.tensor(S3) - sage: T.cell_module_indices(([1,1], [2,1])) + 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 The Cartesian product of (Standard tableaux of shape [1, 1], Standard tableaux of shape [2, 1]) """ @@ -1494,10 +1495,10 @@ def cellular_involution(self): EXAMPLES:: - 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) + 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 ([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] @@ -1547,10 +1548,10 @@ def _to_cellular_element(self, i): EXAMPLES:: - 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 + 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 ....: for k in T.basis().keys()) True """ @@ -1583,11 +1584,11 @@ def _from_cellular_index(self, x): EXAMPLES:: - 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 + 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 ....: 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 4bbdf0807b1..e10e30a5846 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 @@ -55,12 +55,12 @@ def _test_grading(self, **options): sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, # optional - sage.combinat sage.modules ....: nilpotent=True, category=C) - sage: L._test_grading() - sage: L = LieAlgebra(QQ, {('x','y'): {'x': 1}}, + sage: L._test_grading() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('x','y'): {'x': 1}}, # optional - sage.combinat sage.modules ....: nilpotent=True, category=C) - sage: L._test_grading() + sage: L._test_grading() # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: Lie bracket [x, y] has degree 1, not degree 2 @@ -96,9 +96,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}}, + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, # optional - sage.combinat sage.modules ....: nilpotent=True, category=C) - sage: L.homogeneous_component_as_submodule(2) + sage: L.homogeneous_component_as_submodule(2) # optional - sage.combinat sage.modules Sparse vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [0 0 1] @@ -147,12 +147,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) - sage: L._test_generated_by_degree_one() + 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: sc = {('x','y'): {'z': 1}, ('a','b'): {'c':1}, ('z','c'): {'m':1}} - sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) - sage: L._test_generated_by_degree_one() + 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 Traceback (most recent call last): ... AssertionError: [a, b, x, y] does not generate Nilpotent Lie algebra @@ -199,16 +199,16 @@ def degree_on_basis(self, m): 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) - sage: L.degree_on_basis(X.leading_support()) + 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 1 - sage: X.degree() + sage: X.degree() # optional - sage.combinat sage.modules 1 - sage: Y.degree() + sage: Y.degree() # optional - sage.combinat sage.modules 1 - sage: L[X, Y] + sage: L[X, Y] # optional - sage.combinat sage.modules Z - sage: Z.degree() + sage: Z.degree() # optional - sage.combinat sage.modules 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 487924b5748..3637ea46298 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() + sage: C.example() # optional - 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) + sage: C.example(5) # optional - sage.modules An example of a finite dimensional Lie algebra with basis: the 5-dimensional abelian Lie algebra over Rational Field """ @@ -70,27 +70,29 @@ def _construct_UEA(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: UEA = L._construct_UEA(); UEA + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules sage.combinat + sage: UEA = L._construct_UEA(); UEA # optional - sage.modules sage.combinat Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} - sage: UEA.relations(add_commutative=True) + sage: UEA.relations(add_commutative=True) # optional - sage.modules sage.combinat {b1*b0: b0*b1, b2*b0: b0*b2, b2*b1: b1*b2} :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'z':1}, ('y','z'):{'x':1}, ('z','x'):{'y':1}}) - sage: UEA = L._construct_UEA(); UEA + sage: L. = LieAlgebra(QQ, {('x','y'): {'z':1}, # optional - sage.modules sage.combinat + ....: ('y','z'): {'x':1}, + ....: ('z','x'):{'y':1}}) + sage: UEA = L._construct_UEA(); UEA # optional - sage.modules sage.combinat Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - sage: sorted(UEA.relations().items(), key=str) + sage: sorted(UEA.relations().items(), key=str) # optional - sage.modules sage.combinat [(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) - sage: L._construct_UEA() + sage: L = lie_algebras.pwitt(Zmod(6), 6) # optional - sage.modules sage.combinat + sage: L._construct_UEA() # optional - sage.modules sage.combinat Universal enveloping algebra of The 6-Witt Lie algebra over Ring of integers modulo 6 in the Poincare-Birkhoff-Witt basis @@ -147,8 +149,8 @@ def _basis_ordering(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L._basis_ordering + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules sage.combinat + sage: L._basis_ordering # optional - sage.modules sage.combinat (0, 1, 2) """ return tuple(self.basis().keys()) @@ -161,10 +163,10 @@ def _basis_key_inverse(self): EXAMPLES:: - 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] + 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 [0, 1, 2, 3, 4, 5] """ return {k: i for i,k in enumerate(self._basis_ordering)} @@ -175,33 +177,34 @@ def _basis_key(self, x): TESTS:: - sage: L = lie_algebras.three_dimensional_by_rank(QQ, 3, names=['E','F','H']) - sage: PBW = L.pbw_basis() - sage: PBW._basis_key('E') < PBW._basis_key('H') + sage: L = lie_algebras.three_dimensional_by_rank(QQ, 3, # optional - 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 True :: - sage: L = lie_algebras.sl(QQ, 2) - sage: def neg_key(x): + sage: L = lie_algebras.sl(QQ, 2) # optional - sage.groups sage.modules + sage: def neg_key(x): # optional - sage.groups sage.modules ....: return -L.basis().keys().index(x) - sage: PBW = L.pbw_basis(basis_key=neg_key) - sage: prod(PBW.gens()) # indirect doctest + 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 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') - sage: sl2.indices() + sage: sl2 = lie_algebras.sl(QQ, 2, 'matrix') # optional - sage.groups sage.modules + sage: sl2.indices() # optional - sage.groups sage.modules {'e1', 'f1', 'h1'} - sage: type(sl2.basis().keys()) + sage: type(sl2.basis().keys()) # optional - sage.groups sage.modules - sage: Usl2 = sl2.pbw_basis() - sage: Usl2._basis_key(2) + sage: Usl2 = sl2.pbw_basis() # optional - sage.groups sage.modules + sage: Usl2._basis_key(2) # optional - sage.groups sage.modules 2 - sage: Usl2._basis_key(3) + sage: Usl2._basis_key(3) # optional - sage.groups sage.modules Traceback (most recent call last): ... KeyError: 3 @@ -214,8 +217,8 @@ def _dense_free_module(self, R=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L._dense_free_module() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L._dense_free_module() # optional - sage.modules Vector space of dimension 3 over Rational Field """ if R is None: @@ -237,10 +240,10 @@ def from_vector(self, v, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.modules (1, 0, 0) - sage: parent(u) is L + sage: parent(u) is L # optional - sage.modules True """ if order is None: @@ -260,17 +263,17 @@ def killing_matrix(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: L.killing_matrix(a, b) + 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 [0 0 0] [0 0 0] [0 0 0] :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.killing_matrix(y, x) + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.killing_matrix(y, x) # optional - sage.combinat sage.modules [ 0 -1] [ 0 0] """ @@ -291,9 +294,9 @@ def killing_form(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: L.killing_form(a, b) + 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 0 """ return self.killing_matrix(x, y).trace() @@ -309,16 +312,16 @@ def killing_form_matrix(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.killing_form_matrix() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L.killing_form_matrix() # optional - sage.modules [0 0 0] [0 0 0] [0 0 0] - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example(0) - sage: m = L.killing_form_matrix(); m + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example(0) # optional - sage.modules + sage: m = L.killing_form_matrix(); m # optional - sage.modules [] - sage: parent(m) + sage: parent(m) # optional - sage.modules Full MatrixSpace of 0 by 0 dense matrices over Rational Field """ from sage.matrix.constructor import matrix @@ -347,18 +350,18 @@ def structure_coefficients(self, include_zeros=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.structure_coefficients() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L.structure_coefficients() # optional - sage.modules Finite family {} - sage: L.structure_coefficients(True) + sage: L.structure_coefficients(True) # optional - sage.modules Finite family {(0, 1): (0, 0, 0), (0, 2): (0, 0, 0), (1, 2): (0, 0, 0)} :: - sage: G = SymmetricGroup(3) - sage: S = GroupAlgebra(G, QQ) - sage: L = LieAlgebra(associative=S) - sage: L.structure_coefficients() + 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 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), @@ -401,23 +404,23 @@ def centralizer_basis(self, S): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: L.centralizer_basis([a + b, 2*a + c]) + 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 [(1, 0, 0), (0, 1, 0), (0, 0, 1)] - sage: H = lie_algebras.Heisenberg(QQ, 2) - sage: H.centralizer_basis(H) + sage: H = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules + sage: H.centralizer_basis(H) # optional - sage.combinat sage.modules [z] - sage: D = DescentAlgebra(QQ, 4).D() - sage: L = LieAlgebra(associative=D) - sage: L.centralizer_basis(L) + 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 [D{}, D{1} + D{1, 2} + D{2, 3} + D{3}, D{1, 2, 3} + D{1, 3} + D{2}] - sage: D.center_basis() + sage: D.center_basis() # optional - sage.combinat sage.modules (D{}, D{1} + D{1, 2} + D{2, 3} + D{3}, D{1, 2, 3} + D{1, 3} + D{2}) @@ -465,12 +468,12 @@ def centralizer(self, S): EXAMPLES:: - 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 + 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 An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field - sage: S.basis_matrix() + sage: S.basis_matrix() # optional - sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -483,11 +486,11 @@ def center(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: Z = L.center(); Z + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: Z = L.center(); Z # optional - sage.modules An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field - sage: Z.basis_matrix() + sage: Z.basis_matrix() # optional - sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -514,8 +517,8 @@ def derivations_basis(self): We construct the derivations of the Heisenberg Lie algebra:: - sage: H = lie_algebras.Heisenberg(QQ, 1) - sage: H.derivations_basis() + sage: H = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: H.derivations_basis() # optional - sage.combinat sage.modules ( [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] @@ -524,8 +527,8 @@ def derivations_basis(self): We construct the derivations of `\mathfrak{sl}_2`:: - sage: sl2 = lie_algebras.sl(QQ, 2) - sage: sl2.derivations_basis() + sage: sl2 = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules + sage: sl2.derivations_basis() # optional - sage.combinat sage.modules ( [ 1 0 0] [ 0 1 0] [ 0 0 0] [ 0 0 0] [ 0 0 -1/2] [ 1 0 0] @@ -534,9 +537,9 @@ def derivations_basis(self): We verify these are derivations:: - sage: D = [sl2.module_morphism(matrix=M, codomain=sl2) + sage: D = [sl2.module_morphism(matrix=M, codomain=sl2) # optional - sage.combinat sage.modules ....: for M in sl2.derivations_basis()] - sage: all(d(a.bracket(b)) == d(a).bracket(b) + a.bracket(d(b)) + sage: all(d(a.bracket(b)) == d(a).bracket(b) + a.bracket(d(b)) # optional - sage.combinat sage.modules ....: for a in sl2.basis() for b in sl2.basis() for d in D) True @@ -578,8 +581,8 @@ def inner_derivations_basis(self): EXAMPLES:: - sage: H = lie_algebras.Heisenberg(QQ, 1) - sage: H.inner_derivations_basis() + sage: H = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: H.inner_derivations_basis() # optional - sage.combinat sage.modules ( [0 0 0] [0 0 0] [0 0 0] [0 0 0] @@ -606,24 +609,24 @@ def subalgebra(self, *gens, **kwds): EXAMPLES:: - 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() + 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 [p1, q1, z] - sage: S.basis_matrix() + sage: S.basis_matrix() # optional - sage.combinat sage.modules [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) - 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() + 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 [X_12] """ from sage.algebras.lie_algebras.subalgebra import LieSubalgebra_finite_dimensional_with_basis @@ -645,21 +648,21 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - 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() + 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 [-p1 + p2, -q1 + q2, z] - sage: I.reduce(p1 + p2 + q1 + q2 + z) + sage: I.reduce(p1 + p2 + q1 + q2 + z) # optional - sage.combinat sage.modules 2*p1 + 2*q1 Passing an extra category to an ideal:: - 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() + 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 [x, y] """ from sage.algebras.lie_algebras.subalgebra import LieSubalgebra_finite_dimensional_with_basis @@ -676,18 +679,18 @@ def is_ideal(self, A): EXAMPLES:: - 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) + 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 True - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.is_ideal(L) + sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) # optional - sage.combinat sage.modules + sage: L.is_ideal(L) # optional - sage.combinat sage.modules True - sage: F = LieAlgebra(QQ, 'F', representation='polynomial') - sage: L.is_ideal(F) + sage: F = LieAlgebra(QQ, 'F', representation='polynomial') # optional - sage.combinat sage.modules + sage: L.is_ideal(F) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: A must be a finite dimensional Lie algebra @@ -728,26 +731,27 @@ 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) - 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() - [X, Y, Z, W] - sage: E(X).bracket(E(Y)) - Z - sage: Y.bracket(Z) - -U - sage: E(Y).bracket(E(Z)) - 0 - sage: E(U) - 0 + sage: L. = LieAlgebra(QQ, 2, step=3) # optional - sage.combinat sage.modules + sage: E = L.quotient(U); E # optional - sage.combinat sage.modules + 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 + [X, Y, Z, W] + sage: E(X).bracket(E(Y)) # optional - sage.combinat sage.modules + Z + sage: Y.bracket(Z) # optional - sage.combinat sage.modules + -U + sage: E(Y).bracket(E(Z)) # optional - sage.combinat sage.modules + 0 + sage: E(U) # optional - sage.combinat sage.modules + 0 Quotients when the base ring is not a field are not implemented:: - sage: L = lie_algebras.Heisenberg(ZZ, 1) - sage: L.quotient(L.an_element()) + sage: L = lie_algebras.Heisenberg(ZZ, 1) # optional - sage.combinat sage.modules + sage: L.quotient(L.an_element()) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: quotients over non-fields not implemented @@ -769,44 +773,46 @@ def product_space(self, L, submodule=False): EXAMPLES:: - 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) + 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 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]) - sage: X.product_space(Y) + 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 An example of a finite dimensional Lie algebra with basis: - the 0-dimensional abelian Lie algebra over Rational - Field with basis matrix: - [] + the 0-dimensional abelian Lie algebra over Rational Field + with basis matrix: [] :: - 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] + 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 [z] :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: Lp = L.product_space(L) # todo: not implemented - #17416 - sage: Lp # todo: not implemented - #17416 - 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 - 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 - 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 - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - () + 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 + 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 + 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 + 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 + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: () """ from sage.matrix.constructor import matrix @@ -843,8 +849,8 @@ def derived_subalgebra(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.derived_subalgebra() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.derived_subalgebra() # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: the 0-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -852,10 +858,10 @@ def derived_subalgebra(self): If ``self`` is semisimple, then the derived subalgebra is ``self``:: - sage: sl3 = LieAlgebra(QQ, cartan_type=['A',2]) - sage: sl3.derived_subalgebra() + sage: sl3 = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules + sage: sl3.derived_subalgebra() # optional - sage.combinat sage.modules Lie algebra of ['A', 2] in the Chevalley basis - sage: sl3 is sl3.derived_subalgebra() + sage: sl3 is sl3.derived_subalgebra() # optional - sage.combinat sage.modules True """ @@ -894,24 +900,25 @@ def derived_series(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.derived_series() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.derived_series() # optional - sage.combinat sage.modules (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: the 0-dimensional abelian Lie algebra over Rational Field - with basis matrix: - []) + with basis matrix: []) :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.derived_series() # todo: not implemented - #17416 + 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 (Lie algebra on 2 generators (x, y) over Rational Field, - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - (x,), - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - ()) + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: (x,), + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: ()) """ L = [self] while L[-1].dimension() > 0: @@ -952,31 +959,30 @@ def lower_central_series(self, submodule=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.derived_series() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.derived_series() # optional - sage.combinat sage.modules (An example of a finite dimensional Lie algebra with basis: - the 3-dimensional abelian Lie algebra over Rational Field, + the 3-dimensional abelian Lie algebra over Rational Field, An example of a finite dimensional Lie algebra with basis: - the 0-dimensional abelian Lie algebra over Rational Field - with basis matrix: - []) + the 0-dimensional abelian Lie algebra over Rational Field + with basis matrix: []) The lower central series as submodules:: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.lower_central_series(submodule=True) + 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 (Sparse vector space of dimension 2 over Rational Field, - Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [1 0]) + Vector space of degree 2 and dimension 1 over Rational Field + Basis matrix: [1 0]) :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.lower_central_series() # todo: not implemented - #17416 + 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 (Lie algebra on 2 generators (x, y) over Rational Field, - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - (x,)) + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: (x,)) """ if submodule: L = [self.module()] @@ -995,14 +1001,14 @@ def is_abelian(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_abelian() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) - sage: L.is_abelian() + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules False """ return len(self.structure_coefficients()) == 0 @@ -1018,14 +1024,14 @@ def is_solvable(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_solvable() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_solvable() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.is_solvable() # todo: not implemented - #17416 + 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 False """ return not self.derived_series()[-1].dimension() @@ -1039,8 +1045,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_nilpotent() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_nilpotent() # optional - sage.combinat sage.modules True """ return not self.lower_central_series()[-1].dimension() @@ -1055,8 +1061,8 @@ def is_semisimple(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_semisimple() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_semisimple() # optional - sage.combinat sage.modules False """ return not self.killing_form_matrix().is_singular() @@ -1101,24 +1107,24 @@ def chevalley_eilenberg_complex(self, M=None, dual=False, sparse=True, ncpus=Non EXAMPLES:: - sage: L = lie_algebras.sl(ZZ, 2) - sage: C = L.chevalley_eilenberg_complex(); C + sage: L = lie_algebras.sl(ZZ, 2) # optional - sage.combinat sage.modules + sage: C = L.chevalley_eilenberg_complex(); C # optional - sage.combinat sage.modules Chain complex with at most 4 nonzero terms over Integer Ring - sage: ascii_art(C) + sage: ascii_art(C) # optional - sage.combinat sage.modules [ 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]) - sage: C = L.chevalley_eilenberg_complex() # long time - sage: [C.free_module_rank(i) for i in range(11)] # long time + 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 [1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1] - 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()) + 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 [0] [0 0] [2] 0 <-- C_0 <------ C_1 <---- C_2 <-- 0 @@ -1269,15 +1275,15 @@ def homology(self, deg=None, M=None, sparse=True, ncpus=None): EXAMPLES:: - sage: L = lie_algebras.cross_product(QQ) - sage: L.homology() + sage: L = lie_algebras.cross_product(QQ) # optional - sage.combinat sage.modules + sage: L.homology() # optional - sage.combinat sage.modules {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) - sage: L.homology() + 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 {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, @@ -1285,9 +1291,9 @@ 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}} - sage: L. = LieAlgebra(ZZ, d) - sage: L.homology() + 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 {0: Z, 1: Z x C2, 2: 0} .. SEEALSO:: @@ -1334,8 +1340,8 @@ def cohomology(self, deg=None, M=None, sparse=True, ncpus=None): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 4) - sage: L.cohomology() + sage: L = lie_algebras.so(QQ, 4) # optional - sage.combinat sage.modules + sage: L.cohomology() # optional - sage.combinat sage.modules {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, @@ -1344,8 +1350,8 @@ 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) - sage: L.cohomology() + sage: L = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules + sage: L.cohomology() # optional - sage.combinat sage.modules {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, @@ -1353,9 +1359,9 @@ 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}} - sage: L. = LieAlgebra(ZZ, d) - sage: L.cohomology() + 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 {0: Z, 1: Z, 2: C2} .. SEEALSO:: @@ -1376,13 +1382,13 @@ def as_finite_dimensional_algebra(self): EXAMPLES:: - 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) + 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 Z - sage: X * Y + sage: X * Y # optional - sage.combinat sage.modules Z """ from sage.matrix.constructor import matrix @@ -1436,9 +1442,10 @@ 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}, ('X','Z'): {'W':1}}) - sage: K. = LieAlgebra(QQ, abelian=True) - sage: L.morphism({X: A, Y: B}) + sage: L. = LieAlgebra(QQ, {('X','Y'): {'Z': 1}, # optional - sage.combinat sage.modules + ....: ('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 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 @@ -1450,7 +1457,7 @@ 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}) + sage: K.morphism({A:X, B: Y}) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: this does not define a Lie algebra morphism; @@ -1460,15 +1467,16 @@ 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[] - 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) - sage: phi = L.morphism({X: A, Y: B}, base_map=cc) - sage: phi(X) + 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 + ....: ('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 A - sage: phi(i*X) + sage: phi(i*X) # optional - sage.combinat sage.modules sage.rings.number_fields -i*A """ from sage.algebras.lie_algebras.morphism import LieAlgebraMorphism_from_generators @@ -1497,13 +1505,13 @@ def universal_polynomials(self): EXAMPLES:: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) - sage: L.universal_polynomials() + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.universal_polynomials() # optional - sage.combinat sage.modules Finite family {('x', 'x', 'y'): X01*X10 - X00*X11 + X00, ('y', 'x', 'y'): X10} - sage: L = LieAlgebra(QQ, cartan_type=['A',1]) - sage: list(L.universal_polynomials()) + sage: L = LieAlgebra(QQ, cartan_type=['A',1]) # optional - sage.combinat sage.modules + sage: list(L.universal_polynomials()) # optional - sage.combinat sage.modules [-2*X01*X10 + 2*X00*X11 - 2*X00, -2*X02*X10 + 2*X00*X12 + X01, -2*X02*X11 + 2*X01*X12 - 2*X02, @@ -1514,13 +1522,13 @@ 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]) - sage: al = RootSystem(['B',2]).root_lattice().simple_roots() - sage: k = list(L.basis().keys())[0] - sage: UP = L.universal_polynomials() # long time - sage: len(UP) # long time + 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 450 - sage: UP[al[2],al[1],-al[1]] # long time + sage: UP[al[2], al[1], -al[1]] # long time # optional - sage.combinat sage.modules 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 """ @@ -1574,12 +1582,12 @@ def universal_commutative_algebra(self): EXAMPLES:: - 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) + 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 (X00bar, X01bar, 0, X11bar) - sage: a*d - a + sage: a*d - a # optional - sage.combinat sage.modules 0 """ P = list(self.universal_polynomials()) @@ -1593,31 +1601,31 @@ def adjoint_matrix(self, sparse=False): # In #11111 (more or less) by using matr EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.an_element().adjoint_matrix() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.an_element().adjoint_matrix() # optional - sage.combinat sage.modules [0 0 0] [0 0 0] [0 0 0] - sage: L.an_element().adjoint_matrix(sparse=True).is_sparse() + sage: L.an_element().adjoint_matrix(sparse=True).is_sparse() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: x.adjoint_matrix() + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: x.adjoint_matrix() # optional - sage.combinat sage.modules [0 1] [0 0] - sage: y.adjoint_matrix() + sage: y.adjoint_matrix() # optional - sage.combinat sage.modules [-1 0] [ 0 0] We verify that this forms a representation:: - 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() + 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 True """ from sage.matrix.constructor import matrix @@ -1640,16 +1648,16 @@ def to_vector(self, order=None, sparse=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.an_element().to_vector() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.an_element().to_vector() # optional - sage.combinat sage.modules (0, 0, 0) - sage: L.an_element().to_vector(sparse=True) + sage: L.an_element().to_vector(sparse=True) # optional - sage.combinat sage.modules (0, 0, 0) - sage: D = DescentAlgebra(QQ, 4).D() - sage: L = LieAlgebra(associative=D) - sage: L.an_element().to_vector() + 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 (1, 1, 1, 1, 1, 1, 1, 1) TESTS: @@ -1657,13 +1665,13 @@ 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') - sage: x = L.an_element() - sage: x.monomial_coefficients() + 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 Traceback (most recent call last): ... NotImplementedError: the basis is not defined - sage: x.to_vector() + sage: x.to_vector() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: the basis is not defined @@ -1697,10 +1705,11 @@ def ambient(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: S = L.subalgebra([2*a+b, b + c]) - sage: S.ambient() == L + 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 True """ @@ -1711,10 +1720,11 @@ def basis_matrix(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: S = L.subalgebra([2*a+b, b + c]) - sage: S.basis_matrix() + 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 [ 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 0ebca2f2dde..573aec237a1 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']) - sage: F.gens() + sage: F = CombinatorialFreeModule(ZZ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.gens() # optional - sage.modules (B['a'], B['b'], B['c']) """ return tuple(self.basis()) @@ -91,35 +91,35 @@ def annihilator(self, S, action=operator.mul, side='right', category=None): EXAMPLES:: - sage: F = FiniteDimensionalAlgebrasWithBasis(QQ).example(); F + sage: F = FiniteDimensionalAlgebrasWithBasis(QQ).example(); F # optional - 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 - sage: x,y,a,b = F.basis() - sage: A = F.annihilator([a + 3*b + 2*y]); A + sage: x, y, a, b = F.basis() # optional - sage.modules + sage: A = F.annihilator([a + 3*b + 2*y]); A # optional - sage.modules Free module generated by {0} over Rational Field - sage: [b.lift() for b in A.basis()] + sage: [b.lift() for b in A.basis()] # optional - sage.modules [-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, + sage: center = F.annihilator(F.basis(), F.bracket, # optional - sage.modules ....: category=Algebras(QQ).Subobjects()) - sage: (e,) = center.basis() - sage: e.lift() + sage: (e,) = center.basis() # optional - sage.modules + sage: e.lift() # optional - sage.modules x + y - sage: e * e == e + sage: e * e == e # optional - sage.modules True Taking annihilator is order reversing for inclusion:: - 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"))) - sage: sorted(P.cover_relations(), key=str) + 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 [[Ax, A], [Axy, Ax], [Axy, Ay], [Ay, A]] """ return self.submodule(self.annihilator_basis(S, action, side), @@ -204,7 +204,8 @@ def annihilator_basis(self, S, action=operator.mul, side='right'): compute the orthogonal of a subspace:: 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: 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) (x - y, a - b) @@ -251,13 +252,13 @@ def _dense_free_module(self, base_ring=None): EXAMPLES:: - sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']); C + sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']); C # optional - sage.modules Free module generated by {'a', 'b', 'c'} over Univariate Polynomial Ring in x over Rational Field - sage: C._dense_free_module() + sage: C._dense_free_module() # optional - 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']) + sage: C._dense_free_module(QQ['x,y']) # optional - sage.modules Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring in x, y over Rational Field """ @@ -272,11 +273,11 @@ def from_vector(self, vector, order=None, coerce=True): EXAMPLES:: - 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])) + 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 + ....: 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 p + 2*z """ if order is None: @@ -312,42 +313,42 @@ def echelon_form(self, elements, row_reduced=False, order=None): EXAMPLES:: - 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 + 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 [x[0] - x[2], x[1] - x[2]] - sage: matrix(list(map(vector, V))) + sage: matrix(list(map(vector, V))) # optional - sage.modules [ 1 0 -1] [ 0 1 -1] :: - 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) + 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 [B[1] - 17*B[2] + B[4], 6*B[3] - B[4]] :: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: a,b,c = F.basis() - sage: F.echelon_form([8*a+b+10*c, -3*a+b-c, a-b-c]) + 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 [B['a'] + B['c'], B['b'] + 2*B['c']] :: sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, range(3), prefix='x') - sage: x = C.basis() - sage: C.echelon_form([x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]) + 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 [x[0] - x[2], x[1] - x[2]] :: - sage: M = MatrixSpace(QQ, 3, 3) - sage: A = M([[0, 0, 2], [0, 0, 0], [0, 0, 0]]) - sage: M.echelon_form([A, A]) + 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 [ [0 0 1] [0 0 0] @@ -358,8 +359,8 @@ def echelon_form(self, elements, row_reduced=False, order=None): We convert the input elements to ``self``:: - sage: E. = ExteriorAlgebra(QQ) - sage: E.echelon_form([1, x + 2]) + sage: E. = ExteriorAlgebra(QQ) # optional - sage.modules sage.combinat + sage: E.echelon_form([1, x + 2]) # optional - sage.modules sage.combinat [1, x] """ # Make sure elements consists of elements of ``self`` @@ -410,35 +411,37 @@ 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') - sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') + 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)) - sage: I = M.invariant_module(G, action_on_basis=action); I + sage: I = M.invariant_module(G, action_on_basis=action); I # optional - sage.groups sage.modules (S3)-invariant submodule of M - sage: I.basis() + sage: I.basis() # optional - sage.groups sage.modules Finite family {0: B[0]} - sage: [I.lift(b) for b in I.basis()] + sage: [I.lift(b) for b in I.basis()] # optional - sage.groups sage.modules [M[1] + M[2] + M[3]] - sage: G.rename(); M.rename() # reset the names + sage: G.rename(); M.rename() # reset the names # optional - sage.groups sage.modules 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) - 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() + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: H = G.subgroup(G.gen(0)) # optional - sage.groups + sage: H # optional - sage.groups + Subgroup generated by [(1,2,3,4)] + of (Dihedral group of order 8 as a permutation group) + sage: H.cardinality() # optional - sage.groups 4 - sage: A = G.algebra(QQ) - sage: I = A.invariant_module(H) - sage: [I.lift(b) for b in I.basis()] + 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 [() + (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) for b in I.basis() for h in H) + sage: all(h * I.lift(b) == I.lift(b) # optional - sage.groups sage.modules + ....: for b in I.basis() for h in H) True """ if action_on_basis is not None: @@ -480,12 +483,13 @@ def twisted_invariant_module(self, G, chi, EXAMPLES:: - 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], action_on_basis=action) + sage: M = CombinatorialFreeModule(QQ, [1,2,3]) # optional - sage.groups sage.modules + sage: G = SymmetricGroup(3) # optional - sage.groups + 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 + ....: action_on_basis=action) sage: import __main__; __main__.action = action - sage: TestSuite(T).run() + sage: TestSuite(T).run() # optional - sage.groups sage.modules """ if action_on_basis is not None: @@ -514,12 +518,12 @@ def dense_coefficient_list(self, order=None): EXAMPLES:: - sage: v = vector([0, -1, -3]) - sage: v.dense_coefficient_list() + sage: v = vector([0, -1, -3]) # optional - sage.modules + sage: v.dense_coefficient_list() # optional - sage.modules [0, -1, -3] - sage: v.dense_coefficient_list([2,1,0]) + sage: v.dense_coefficient_list([2,1,0]) # optional - sage.modules [-3, -1, 0] - sage: sorted(v.coefficients()) + sage: sorted(v.coefficients()) # optional - sage.modules [-3, -1] """ if order is None: @@ -535,11 +539,11 @@ def _vector_(self, order=None): EXAMPLES:: - sage: v = vector([0, -1, -3]) - sage: v._vector_() + sage: v = vector([0, -1, -3]) # optional - sage.modules + sage: v._vector_() # optional - sage.modules (0, -1, -3) - sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']) - sage: C.an_element()._vector_() + sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']) # optional - sage.modules + sage: C.an_element()._vector_() # optional - sage.modules (2, 2, 3) """ if order is None: @@ -577,30 +581,31 @@ def matrix(self, base_ring=None, side="left"): EXAMPLES:: - 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() + 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 + ....: 2: 2*y[3] + 5*y[4]}.__getitem__, + ....: codomain=Y) + sage: phi.matrix() # optional - sage.modules [1 2] [3 5] - sage: phi.matrix(side="right") + sage: phi.matrix(side="right") # optional - sage.modules [1 3] [2 5] - sage: phi.matrix().parent() + sage: phi.matrix().parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: phi.matrix(QQ).parent() + sage: phi.matrix(QQ).parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field The resulting matrix is immutable:: - sage: phi.matrix().is_mutable() + sage: phi.matrix().is_mutable() # optional - sage.modules False The zero morphism has a zero matrix:: - sage: Hom(X,Y).zero().matrix() + sage: Hom(X, Y).zero().matrix() # optional - sage.modules [0 0] [0 0] @@ -609,10 +614,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() - sage: phi = X.module_morphism(on_basis = {1: y[3] + 3*y[4], 2: 2*y[3] + 5/2*y[4]}.__getitem__, - ....: codomain = Y) - sage: phi.matrix().parent() # todo: not implemented + 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 + ....: 2: 2*y[3] + 5/2*y[4]}.__getitem__, + ....: codomain=Y) + sage: phi.matrix().parent() # todo: not implemented # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field This currently does not work because, in this case, @@ -620,20 +626,20 @@ 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() + sage: phi.parent().homset_category() # optional - sage.modules Category of commutative additive semigroups - sage: phi.parent().homset_category() # todo: not implemented + sage: phi.parent().homset_category() # todo: not implemented # optional - sage.modules Category of finite dimensional modules with basis over Integer Ring TESTS: Check that :trac:`23216` is fixed:: - sage: X = CombinatorialFreeModule(QQ, []) - sage: Y = CombinatorialFreeModule(QQ, [1,2,3]) - sage: Hom(X,Y).zero().matrix() + 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: Hom(X,Y).zero().matrix().parent() + sage: Hom(X, Y).zero().matrix().parent() # optional - sage.modules Full MatrixSpace of 3 by 0 dense matrices over Rational Field """ if base_ring is None: @@ -663,41 +669,41 @@ def __invert__(self): EXAMPLES:: sage: category = FiniteDimensionalModulesWithBasis(ZZ) - 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 - sage: psi + 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 + ....: codomain=Y, category=category) + sage: psi = ~phi # optional - sage.modules + sage: psi # optional - sage.modules Generic morphism: From: Y To: X - sage: psi.parent() + sage: psi.parent() # optional - sage.modules Set of Morphisms from Y to X in Category of finite dimensional modules with basis over Integer Ring - sage: psi(y[3]) + sage: psi(y[3]) # optional - sage.modules -5*B[1] + 3*B[2] - sage: psi(y[4]) + sage: psi(y[4]) # optional - sage.modules 2*B[1] - B[2] - sage: psi.matrix() + sage: psi.matrix() # optional - sage.modules [-5 2] [ 3 -1] - sage: psi(phi(x[1])), psi(phi(x[2])) + sage: psi(phi(x[1])), psi(phi(x[2])) # optional - sage.modules (B[1], B[2]) - sage: phi(psi(y[3])), phi(psi(y[4])) + sage: phi(psi(y[3])), phi(psi(y[4])) # optional - sage.modules (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__, - ....: codomain = Y, category = category) - sage: ~phi + sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + y[4]}.__getitem__, # optional - sage.modules + ....: codomain=Y, category=category) + sage: ~phi # optional - 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__, - ....: codomain = Y, category = category) - sage: ~phi + sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + 5*y[4]}.__getitem__, # optional - sage.modules + ....: codomain=Y, category=category) + sage: ~phi # optional - sage.modules Traceback (most recent call last): ... RuntimeError: morphism is not invertible @@ -717,9 +723,9 @@ def kernel_basis(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: f.kernel_basis() + 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 ([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, @@ -731,12 +737,12 @@ def kernel(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: K = f.kernel() - sage: K + 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 Free module generated by {0, 1, 2} over Rational Field - sage: K.ambient() + sage: K.ambient() # optional - sage.groups sage.modules Symmetric group algebra of order 3 over Rational Field """ D = self.domain() @@ -749,9 +755,9 @@ def image_basis(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: f.image_basis() + 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 ([1, 2, 3], [2, 3, 1], [3, 1, 2]) """ C = self.codomain() @@ -763,9 +769,9 @@ def image(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: f.image() + 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 Free module generated by {0, 1, 2} over Rational Field """ C = self.codomain() @@ -781,10 +787,12 @@ def extra_super_categories(self): EXAMPLES:: - sage: ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts().extra_super_categories() + sage: C = ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts() + sage: C.extra_super_categories() [Category of finite dimensional modules with basis over Integer Ring] - sage: ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts().FiniteDimensional() - Category of tensor products of finite dimensional modules with basis over Integer Ring + sage: C.FiniteDimensional() + Category of tensor products of + finite dimensional modules with basis over Integer Ring """ return [self.base_category()] 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 fe0ad9f3d21..d294ec75fae 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,16 +60,17 @@ def _test_nilpotency(self, **options): EXAMPLES:: - 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() + 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 + ....: nilpotent=True, step=3) + sage: L._test_nilpotency() # optional - sage.combinat sage.modules 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) - sage: L._test_nilpotency() + 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 Traceback (most recent call last): ... AssertionError: final term of lower central series is non-zero @@ -100,28 +101,29 @@ def lie_group(self, name='G', **kwds): We define the Heisenberg group:: - sage: L = lie_algebras.Heisenberg(QQ, 1) - sage: G = L.lie_group('G'); G # optional - sage.symbolic + 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 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.symbolic - sage: g = G.exp(p); g # optional - sage.symbolic + 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 exp(p1) - sage: h = G.exp(q); h # optional - sage.symbolic + sage: h = G.exp(q); h # optional - sage.combinat sage.modules sage.symbolic exp(q1) - sage: g*h # optional - sage.symbolic + sage: g * h # optional - sage.combinat sage.modules sage.symbolic 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.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.symbolic + sage: X = G.left_invariant_extension(2*p + 3*q, name='X'); X # optional - 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 X = 2 ∂/∂x_0 + 3 ∂/∂x_1 - sage: X.display() # optional - sage.symbolic + sage: X.display() # optional - sage.combinat sage.modules sage.symbolic X = 2 ∂/∂x_0 + 3 ∂/∂x_1 + (3/2*x_0 - x_1) ∂/∂x_2 .. SEEALSO:: @@ -137,11 +139,11 @@ def step(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) - sage: L.step() + sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules + sage: L.step() # optional - sage.combinat sage.modules 2 - sage: sc = {('X','Y'): {'Z': 1}, ('X','Z'): {'W': 1}} - sage: LieAlgebra(QQ, sc, nilpotent=True).step() + 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 3 """ if not hasattr(self, '_step'): @@ -154,8 +156,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, nilpotent=True) - sage: L.is_nilpotent() + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules + sage: L.is_nilpotent() # optional - 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 59ab6a9a8ad..56303fc5eb0 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) - sage: A.radical_basis() + sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules + sage: A.radical_basis() # optional - sage.groups sage.modules () TESTS:: - sage: A.radical_basis.__module__ + sage: A.radical_basis.__module__ # optional - sage.groups sage.modules 'sage.categories.finite_dimensional_semisimple_algebras_with_basis' """ return () @@ -81,25 +81,25 @@ 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) - sage: A3 = AlternatingGroup(3).algebra(R) - sage: idempotents = A3.central_orthogonal_idempotents() - sage: idempotents + 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 (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) + sage: A3.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.rings.number_field sage.groups True For the semisimple quotient of a quiver algebra, we recover the vertices of the quiver:: - sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A + sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A # optional - sage.combinat 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() - sage: Aquo.central_orthogonal_idempotents() + sage: Aquo = A.semisimple_quotient() # optional - sage.combinat + sage: Aquo.central_orthogonal_idempotents() # optional - sage.combinat (B['x'], B['y']) """ return tuple([x.lift() @@ -157,8 +157,8 @@ def _orthogonal_decomposition(self, generators=None): center of the algebra of the symmetric group `S_4`:: - sage: Z4 = SymmetricGroup(4).algebra(QQ).center() - sage: Z4._orthogonal_decomposition() + sage: Z4 = SymmetricGroup(4).algebra(QQ).center() # optional - sage.groups sage.modules + sage: Z4._orthogonal_decomposition() # optional - 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 +219,10 @@ def central_orthogonal_idempotents(self): EXAMPLES:: - sage: A4 = SymmetricGroup(4).algebra(QQ) - sage: Z4 = A4.center() - sage: idempotents = Z4.central_orthogonal_idempotents() - sage: idempotents + 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 (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 +233,7 @@ def central_orthogonal_idempotents(self): recognize among them the sum and alternating sum of all permutations:: - sage: [e.lift() for e in idempotents] + sage: [e.lift() for e in idempotents] # optional - 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 +251,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) + sage: Z4.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - 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 4a872cf2fbf..4d90a3cd3f9 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)) + sage: FiniteEnumeratedSets()(GF(3)) # optional - sage.rings.finite_rings Finite Field of size 3 - sage: Partitions(3) + sage: Partitions(3) # optional - 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)) + sage: len(GF(5)) # optional - sage.rings.finite_rings 5 - sage: len(MatrixSpace(GF(2), 3, 3)) + sage: len(MatrixSpace(GF(2), 3, 3)) # optional - sage.rings.finite_rings 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)]) - sage: C in EnumeratedSets().Finite() + sage: C = cartesian_product([Partitions(10), Permutations(20)]) # optional - sage.combinat + sage: C in EnumeratedSets().Finite() # optional - sage.combinat True - sage: C.random_element.__module__ + sage: C.random_element.__module__ # optional - sage.combinat 'sage.categories.sets_cat' - sage: C.cardinality.__module__ + sage: C.cardinality.__module__ # optional - sage.combinat 'sage.categories.sets_cat' - sage: C.__iter__.__module__ + sage: C.__iter__.__module__ # optional - sage.combinat 'sage.categories.sets_cat' """ random_element = raw_getattr(Sets.CartesianProducts.ParentMethods, "random_element") @@ -613,8 +613,9 @@ def last(self): EXAMPLES:: - sage: C = cartesian_product([Zmod(42), Partitions(10), IntegerRange(5)]) - sage: C.last() + sage: C = cartesian_product([Zmod(42), Partitions(10), # optional - sage.combinat + ....: IntegerRange(5)]) + sage: C.last() # optional - sage.combinat (41, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 4) """ return self._cartesian_product_of_elements( @@ -635,13 +636,13 @@ def rank(self, x): EXAMPLES:: - sage: C = cartesian_product([GF(2), GF(11), GF(7)]) - sage: C.rank(C((1,2,5))) + 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 96 - sage: C.rank(C((0,0,0))) + sage: C.rank(C((0,0,0))) # optional - sage.rings.finite_rings 0 - sage: for c in C: print(C.rank(c)) + sage: for c in C: print(C.rank(c)) # optional - sage.rings.finite_rings 0 1 2 @@ -656,12 +657,12 @@ def rank(self, x): sage: F1 = FiniteEnumeratedSet('abcdefgh') sage: F2 = IntegerRange(250) - sage: F3 = Partitions(20) - sage: C = cartesian_product([F1, F2, F3]) - sage: c = C(('a', 86, [7,5,4,4])) - sage: C.rank(c) + 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 54213 - sage: C.unrank(54213) + sage: C.unrank(54213) # optional - sage.combinat ('a', 86, [7, 5, 4, 4]) """ from builtins import zip @@ -691,18 +692,18 @@ def unrank(self, i): EXAMPLES:: - sage: C = cartesian_product([GF(3), GF(11), GF(7), GF(5)]) - sage: c = C.unrank(123); c + 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 (0, 3, 3, 3) - sage: C.rank(c) + sage: C.rank(c) # optional - sage.rings.finite_rings 123 - sage: c = C.unrank(857); c + sage: c = C.unrank(857); c # optional - sage.rings.finite_rings (2, 2, 3, 2) - sage: C.rank(c) + sage: C.rank(c) # optional - sage.rings.finite_rings 857 - sage: C.unrank(2500) + sage: C.unrank(2500) # optional - sage.rings.finite_rings 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 25a93c8b960..b685a249780 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 + sage: FiniteField(17) in K # optional - sage.rings.finite_rings True sage: RationalField() in K False @@ -67,7 +67,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in FiniteFields() + sage: GF(4, "a") in FiniteFields() # optional - sage.rings.finite_rings True sage: QQ in FiniteFields() False @@ -82,7 +82,7 @@ def _call_(self, x): """ EXAMPLES:: - sage: FiniteFields()(GF(4, "a")) + sage: FiniteFields()(GF(4, "a")) # optional - 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 42415233567..1d0e7d72357 100644 --- a/src/sage/categories/finite_groups.py +++ b/src/sage/categories/finite_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.groups r""" Finite groups """ diff --git a/src/sage/categories/finite_lattice_posets.py b/src/sage/categories/finite_lattice_posets.py index 4b7f0fb9b28..1bb0de98fad 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]}) - sage: L.join_irreducibles() + 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 [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]}) - sage: L.join_irreducibles_poset() + 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 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]}) - sage: L.meet_irreducibles() + 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 [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]}) - sage: L.join_irreducibles_poset() + 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 Finite poset containing 3 elements .. SEEALSO:: @@ -143,20 +143,20 @@ def irreducibles_poset(self): EXAMPLES:: - sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], + sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], # optional - sage.combinat sage.graphs ....: 4: [6], 5: [9, 7], 6: [9, 8], 7: [10], ....: 8: [10], 9: [10], 10: [11]}) - sage: L_ = L.irreducibles_poset() - sage: sorted(L_) + sage: L_ = L.irreducibles_poset() # optional - sage.combinat sage.graphs + sage: sorted(L_) # optional - sage.combinat sage.graphs [2, 3, 4, 7, 8, 9, 10, 11] - sage: L_.completion_by_cuts().is_isomorphic(L) + sage: L_.completion_by_cuts().is_isomorphic(L) # optional - sage.combinat sage.graphs True TESTS:: - sage: LatticePoset().irreducibles_poset() + sage: LatticePoset().irreducibles_poset() # optional - sage.combinat sage.graphs Finite poset containing 0 elements - sage: posets.ChainPoset(1).irreducibles_poset() + sage: posets.ChainPoset(1).irreducibles_poset() # optional - sage.combinat sage.graphs Finite poset containing 1 elements """ if self.cardinality() == 1: @@ -191,35 +191,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"))) - sage: B = LatticePoset((Subsets([2,2,3]), attrcall("issubset"))) - sage: def f(b): return D(5*prod(b)) - sage: B.is_lattice_morphism(f, D) + 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 True We construct the boolean lattice `B_2`:: - sage: B = posets.BooleanLattice(2) - sage: B.cover_relations() + sage: B = posets.BooleanLattice(2) # optional - sage.combinat sage.graphs + sage: B.cover_relations() # optional - sage.combinat 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: L = LatticePoset(DiGraph({-1:[0], 0:[1,2], 1:[3], 2:[3],3:[4]})) - sage: L.cover_relations() + 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 [[-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__ - sage: B.is_lattice_morphism(f, L) + 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 True - sage: f = { B(0): L(-1),B(1): L(1), B(2): L(2), B(3): L(3) }.__getitem__ - sage: B.is_lattice_morphism(f, L) + 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 False - sage: f = { B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(4) }.__getitem__ - sage: B.is_lattice_morphism(f, L) + 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 False .. SEEALSO:: diff --git a/src/sage/categories/finite_monoids.py b/src/sage/categories/finite_monoids.py index fdf1db47a71..9531b671249 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) - sage: BSigma2 = Sigma2.nerve() - sage: BSigma2.cohomology(4, base_ring=GF(2)) + 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 Vector space of dimension 1 over Finite Field of size 2 The `k`-simplices of the nerve are named after the chains @@ -83,45 +83,45 @@ 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) + sage: BSigma2.n_cells(1) # optional - sage.groups [(1,2)] - sage: BSigma2.n_cells(2) + sage: BSigma2.n_cells(2) # optional - sage.groups [(1,2) * (1,2)] Another construction of the group, with different names for its elements:: - sage: C2 = groups.misc.MultiplicativeAbelian([2]) - sage: BC2 = C2.nerve() - sage: BC2.n_cells(0) + sage: C2 = groups.misc.MultiplicativeAbelian([2]) # optional - sage.groups + sage: BC2 = C2.nerve() # optional - sage.groups + sage: BC2.n_cells(0) # optional - sage.groups [1] - sage: BC2.n_cells(1) + sage: BC2.n_cells(1) # optional - sage.groups [f] - sage: BC2.n_cells(2) + sage: BC2.n_cells(2) # optional - sage.groups [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) - sage: BSigma3 = Sigma3.nerve() - sage: BSigma3.homology(range(4), base_ring=GF(3)) + 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 {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, - 3: Vector space of dimension 1 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, + 3: Vector space of dimension 1 over Finite Field of size 3} Note that we can construct the `n`-skeleton for `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) + sage: Sigma2.nerve().n_skeleton(14) # optional - sage.groups Simplicial set with 15 non-degenerate simplices - sage: BSigma3 = Sigma3.nerve() - sage: BSigma3.n_skeleton(3) + sage: BSigma3 = Sigma3.nerve() # optional - sage.groups + sage: BSigma3.n_skeleton(3) # optional - sage.groups Simplicial set with 156 non-degenerate simplices - sage: BSigma3.n_skeleton(4) + sage: BSigma3.n_skeleton(4) # optional - sage.groups Simplicial set with 781 non-degenerate simplices Finally, note that the classifying space of the order `p` @@ -129,33 +129,33 @@ def nerve(self): on `p` letters, and its first homology group appears earlier:: - sage: C3 = groups.misc.MultiplicativeAbelian([3]) - sage: list(C3) + sage: C3 = groups.misc.MultiplicativeAbelian([3]) # optional - sage.groups + sage: list(C3) # optional - sage.groups [1, f, f^2] - sage: BC3 = C3.nerve() - sage: BC3.n_cells(1) + sage: BC3 = C3.nerve() # optional - sage.groups + sage: BC3.n_cells(1) # optional - sage.groups [f, f^2] - sage: BC3.n_cells(2) + sage: BC3.n_cells(2) # optional - sage.groups [f * f, f * f^2, f^2 * f, f^2 * f^2] - sage: len(BSigma3.n_cells(2)) + sage: len(BSigma3.n_cells(2)) # optional - sage.groups 25 - sage: len(BC3.n_cells(3)) + sage: len(BC3.n_cells(3)) # optional - sage.groups 8 - sage: len(BSigma3.n_cells(3)) + sage: len(BSigma3.n_cells(3)) # optional - sage.groups 125 - sage: BC3.homology(range(4), base_ring=GF(3)) + sage: BC3.homology(range(4), base_ring=GF(3)) # optional - sage.groups sage.rings.finite_rings {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() - sage: BC5.homology(range(4), base_ring=GF(5)) + 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 {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, - 3: Vector space of dimension 1 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, + 3: Vector space of dimension 1 over Finite Field of size 5} """ from sage.topology.simplicial_set_examples import Nerve return Nerve(self) @@ -179,20 +179,20 @@ def rhodes_radical_congruence(self, base_ring=None): EXAMPLES:: sage: M = Monoids().Finite().example() - sage: M.rhodes_radical_congruence() + sage: M.rhodes_radical_congruence() # optional - sage.groups sage.modules [(0, 6), (2, 8), (4, 10)] - 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() + 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 [([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() + sage: SymmetricGroup(3).rhodes_radical_congruence() # optional - sage.groups sage.modules [] - sage: DihedralGroup(10).rhodes_radical_congruence() + sage: DihedralGroup(10).rhodes_radical_congruence() # optional - sage.groups sage.modules [] REFERENCES: diff --git a/src/sage/categories/finite_permutation_groups.py b/src/sage/categories/finite_permutation_groups.py index 59c00471e3f..e081d2d4f63 100644 --- a/src/sage/categories/finite_permutation_groups.py +++ b/src/sage/categories/finite_permutation_groups.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.groups r""" Finite Permutation Groups """ diff --git a/src/sage/categories/finite_posets.py b/src/sage/categories/finite_posets.py index b5422adfd4e..263033a2c9b 100644 --- a/src/sage/categories/finite_posets.py +++ b/src/sage/categories/finite_posets.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Finite posets diff --git a/src/sage/categories/finite_semigroups.py b/src/sage/categories/finite_semigroups.py index a7f9b9a20a1..e9c31e1ad62 100644 --- a/src/sage/categories/finite_semigroups.py +++ b/src/sage/categories/finite_semigroups.py @@ -51,7 +51,8 @@ class FiniteSemigroups(CategoryWithAxiom): sage: sorted(C.axioms()) ['Associative', 'Finite'] sage: C.example() - An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd') + An example of a finite semigroup: + the left regular band generated by ('a', 'b', 'c', 'd') TESTS:: @@ -86,8 +87,9 @@ def j_classes(self): EXAMPLES:: sage: S = FiniteSemigroups().example(alphabet=('a','b', 'c')) - sage: sorted(map(sorted, S.j_classes())) - [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] + sage: sorted(map(sorted, S.j_classes())) # optional - sage.graphs + [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], + ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] """ return self.cayley_graph(side="twosided", simple=True).strongly_connected_components() @@ -103,8 +105,9 @@ def j_classes_of_idempotents(self): EXAMPLES:: sage: S = FiniteSemigroups().example(alphabet=('a','b', 'c')) - sage: sorted(map(sorted, S.j_classes_of_idempotents())) - [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] + sage: sorted(map(sorted, S.j_classes_of_idempotents())) # optional - sage.graphs + [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], + ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] """ return [l for l in ([x for x in cl if attrcall('is_idempotent')(x)] for cl in self.j_classes()) if len(l) > 0] @@ -120,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 + sage: sorted(S.j_transversal_of_idempotents()) # random # optional - 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 4420827c833..1d1d0250c23 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() + sage: TestSuite(W).run() # optional - sage.combinat """ 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 8877491e33e..85315805fad 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() + sage: LambdaBracketAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field Category of finitely generated lambda bracket algebras over Algebraic Field """ _base_category_class_and_axiom = (LambdaBracketAlgebras, "FinitelyGeneratedAsLambdaBracketAlgebra") @@ -38,12 +38,12 @@ def ngens(self): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) - sage: Vir.ngens() + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: Vir.ngens() # optional - sage.combinat sage.modules 2 - sage: V = lie_conformal_algebras.Affine(QQ, 'A2') - sage: V.ngens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A2') # optional - sage.combinat sage.modules + sage: V.ngens() # optional - sage.combinat sage.modules 9 """ return len(self.gens()) @@ -54,12 +54,12 @@ def gen(self,i): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') - sage: V.gens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: V.gens() # optional - sage.combinat sage.modules (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: V.gen(0) + sage: V.gen(0) # optional - sage.combinat sage.modules B[alpha[1]] - sage: V.1 + sage: V.1 # optional - sage.combinat sage.modules B[alphacheck[1]] """ return self.gens()[i] @@ -73,10 +73,11 @@ def some_elements(self): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) - sage: V.some_elements() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + ....: names=('e', 'h', 'f')) + sage: V.some_elements() # optional - sage.combinat sage.modules [e, h, f, K, ...] - sage: all(v.parent() is V for v in V.some_elements()) + sage: all(v.parent() is V for v in V.some_elements()) # optional - sage.combinat sage.modules True """ S = list(self.gens()) @@ -91,8 +92,9 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() - Category of H-graded finitely generated lie conformal algebras over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # optional - sage.rings.number_field + Category of H-graded finitely generated lie conformal algebras + over Algebraic Field """ def _repr_object_names(self): """ @@ -100,7 +102,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - 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 464d1eb7d03..96433749aa4 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() + sage: LieConformalAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field Category of finitely generated lie conformal algebras over Algebraic Field """ _base_category_class_and_axiom = (LieConformalAlgebras, "FinitelyGeneratedAsLambdaBracketAlgebra") @@ -43,10 +43,11 @@ def some_elements(self): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) - sage: V.some_elements() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + ....: names=('e', 'h', 'f')) + sage: V.some_elements() # optional - sage.combinat sage.modules [e, h, f, K, ...] - sage: all(v.parent() is V for v in V.some_elements()) + sage: all(v.parent() is V for v in V.some_elements()) # optional - sage.combinat sage.modules True """ S = list(self.gens()) @@ -61,8 +62,9 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).FinitelyGenerated().Super() - Category of super finitely generated lie conformal algebras over Algebraic Real Field + sage: LieConformalAlgebras(AA).FinitelyGenerated().Super() # optional - sage.rings.number_field + Category of super finitely generated lie conformal algebras + over Algebraic Real Field """ class Graded(GradedModulesCategory): """ @@ -70,8 +72,9 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Super().Graded() - Category of H-graded super finitely generated lie conformal algebras over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Super().Graded() # optional - sage.rings.number_field + Category of H-graded super finitely generated lie conformal algebras + over Algebraic Field """ def _repr_object_names(self): """ @@ -79,9 +82,10 @@ def _repr_object_names(self): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).FinitelyGenerated() - sage: C.Super().Graded() - Category of H-graded super finitely generated lie conformal algebras over Algebraic Field + sage: C = LieConformalAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field + sage: C.Super().Graded() # optional - sage.rings.number_field + Category of H-graded super finitely generated + lie conformal algebras over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) @@ -91,8 +95,9 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() - Category of H-graded finitely generated lie conformal algebras over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # optional - sage.rings.number_field + Category of H-graded finitely generated lie conformal algebras + over Algebraic Field """ def _repr_object_names(self): """ @@ -100,7 +105,8 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() - Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - 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/functor.pyx b/src/sage/categories/functor.pyx index a0e8b42e1bf..58ff4cb21bf 100644 --- a/src/sage/categories/functor.pyx +++ b/src/sage/categories/functor.pyx @@ -112,12 +112,12 @@ cdef class Functor(SageObject): this behaviour. Here we illustrate the default:: sage: from sage.categories.functor import Functor - sage: F = Functor(Rings(),Fields()) + sage: F = Functor(Rings(), Fields()) sage: F Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) + sage: F(GF(2)) # optional - sage.rings.finite_rings Finite Field of size 2 Functors are not only about the objects of a category, but also about @@ -128,7 +128,7 @@ cdef class Functor(SageObject): sage: R1. = ZZ[] sage: R2. = QQ[] - sage: f = R1.hom([a+b],R2) + sage: f = R1.hom([a + b], R2) sage: f Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring @@ -150,8 +150,10 @@ cdef class Functor(SageObject): Poly[t] sage: F(f) Ring morphism: - From: Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring - To: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in a, b over Rational Field + From: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in x over Integer Ring + To: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in a, b over Rational Field Defn: Induced from base ring by Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring @@ -159,7 +161,8 @@ cdef class Functor(SageObject): Defn: x |--> a + b sage: p = R1['t']('(-x^2 + x)*t^2 + (x^2 - x)*t - 4*x^2 - x + 1') sage: F(f)(p) - (-a^2 - 2*a*b - b^2 + a + b)*t^2 + (a^2 + 2*a*b + b^2 - a - b)*t - 4*a^2 - 8*a*b - 4*b^2 - a - b + 1 + (-a^2 - 2*a*b - b^2 + a + b)*t^2 + (a^2 + 2*a*b + b^2 - a - b)*t + - 4*a^2 - 8*a*b - 4*b^2 - a - b + 1 """ def __init__(self, domain, codomain): @@ -167,12 +170,12 @@ cdef class Functor(SageObject): TESTS:: sage: from sage.categories.functor import Functor - sage: F = Functor(Rings(),Fields()) + sage: F = Functor(Rings(), Fields()) sage: F Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) + sage: F(GF(2)) # optional - sage.rings.finite_rings Finite Field of size 2 """ @@ -228,7 +231,7 @@ cdef class Functor(SageObject): TESTS:: sage: from sage.categories.functor import Functor - sage: F = Functor(FiniteFields(),Fields()) + sage: F = Functor(FiniteFields(), Fields()) sage: F._apply_functor(ZZ) Rational Field @@ -248,20 +251,22 @@ cdef class Functor(SageObject): TESTS:: sage: from sage.categories.functor import Functor - sage: F = Functor(Rings(),Fields()) - 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 + 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 + 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 - Ring endomorphism of Univariate Polynomial Ring in t over Finite Field in a of size 5^2 + Ring endomorphism of Univariate Polynomial Ring in t + over Finite Field in a of size 5^2 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)) + sage: fF((a^2+a)*t^2/(a*t - a^2)) # optional - sage.rings.finite_rings ((4*a + 2)*t^2)/(t + a + 4) """ @@ -334,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)) + sage: F(GF(2)) # optional - sage.rings.finite_rings Finite Field of size 2 Two subclasses:: - sage: F1 = ForgetfulFunctor(FiniteFields(),Fields()) - sage: F1(GF(5)) #indirect doctest + sage: F1 = ForgetfulFunctor(FiniteFields(), Fields()) + sage: F1(GF(5)) # indirect doctest # optional - sage.rings.finite_rings Finite Field of size 5 sage: F1(ZZ) Traceback (most recent call last): @@ -352,7 +357,8 @@ cdef class Functor(SageObject): sage: F2(ZZ['x','y']) Traceback (most recent call last): ... - TypeError: x (=Multivariate Polynomial Ring in x, y over Integer Ring) is not in Category of fields + TypeError: x (=Multivariate Polynomial Ring in x, y over Integer Ring) + is not in Category of fields The last example shows that it is tested whether the result of applying the functor lies in the functor's codomain. Note that @@ -360,20 +366,22 @@ cdef class Functor(SageObject): which was fixed in :trac:`8807`:: sage: class IllFunctor(Functor): - ....: def __init__(self, m,n): + ....: def __init__(self, m, n): ....: self._m = m ....: self._n = n - ....: Functor.__init__(self,Rings(),Rings()) + ....: Functor.__init__(self, Rings(), Rings()) ....: def _apply_functor(self, R): - ....: return MatrixSpace(R,self._m,self._n) - sage: F = IllFunctor(2,2) - sage: F(QQ) + ....: return MatrixSpace(R, self._m, self._n) + sage: F = IllFunctor(2, 2) + sage: F(QQ) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: F = IllFunctor(2,3) - sage: F(QQ) + sage: F = IllFunctor(2, 3) + sage: F(QQ) # optional - sage.modules Traceback (most recent call last): ... - TypeError: Functor from Category of rings to Category of rings is ill-defined, since it sends x (=Rational Field) to something that is not in Category of rings. + TypeError: Functor from Category of rings to Category of rings + is ill-defined, since it sends x (=Rational Field) to something + that is not in Category of rings. """ from sage.categories.morphism import is_Morphism @@ -390,7 +398,7 @@ cdef class Functor(SageObject): EXAMPLES:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) sage: F.domain() Category of finite enumerated fields @@ -403,7 +411,7 @@ cdef class Functor(SageObject): EXAMPLES:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) sage: F.codomain() Category of fields @@ -456,10 +464,12 @@ class ForgetfulFunctor_generic(Functor): EXAMPLES:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) #indirect doctest + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) # indirect doctest sage: F - The forgetful functor from Category of finite enumerated fields to Category of fields - sage: F(GF(3)) + The forgetful functor + from Category of finite enumerated fields + to Category of fields + sage: F(GF(3)) # optional - sage.rings.finite_rings Finite Field of size 3 """ @@ -477,9 +487,10 @@ class ForgetfulFunctor_generic(Functor): """ TESTS:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) - sage: F #indirect doctest - The forgetful functor from Category of finite enumerated fields to Category of fields + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) + sage: F # indirect doctest + The forgetful functor from Category of finite enumerated fields + to Category of fields """ return "The forgetful functor from %s to %s" % (self.domain(), @@ -497,7 +508,7 @@ class ForgetfulFunctor_generic(Functor): TESTS:: - sage: F1 = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F1 = ForgetfulFunctor(FiniteFields(), Fields()) This is to test against a bug occurring in a previous version (see :trac:`8800`):: @@ -524,7 +535,7 @@ class ForgetfulFunctor_generic(Functor): EXAMPLES:: - sage: F1 = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F1 = ForgetfulFunctor(FiniteFields(), Fields()) sage: F1 != F1 False sage: F1 != QQ @@ -665,14 +676,17 @@ def ForgetfulFunctor(domain, codomain): sage: abgrps = CommutativeAdditiveGroups() sage: F = ForgetfulFunctor(rings, abgrps) sage: F - The forgetful functor from Category of rings to Category of commutative additive groups + The forgetful functor + from Category of rings + to Category of commutative additive groups It would be a mistake to call it in opposite order:: sage: F = ForgetfulFunctor(abgrps, rings) Traceback (most recent call last): ... - ValueError: Forgetful functor not supported for domain Category of commutative additive groups + ValueError: Forgetful functor not supported for domain + Category of commutative additive groups If both categories are equal, the forgetful functor is the same as the identity functor:: diff --git a/src/sage/categories/g_sets.py b/src/sage/categories/g_sets.py index b9447203e42..0f8004ddbf0 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) - sage: GSets(S) + sage: S = SymmetricGroup(3) # optional - sage.groups + sage: GSets(S) # optional - 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) - sage: TestSuite(GSets(S8)).run() + sage: S8 = SymmetricGroup(8) # optional - sage.groups + sage: TestSuite(GSets(S8)).run() # optional - sage.groups """ Category.__init__(self) self.__G = G @@ -43,7 +43,7 @@ def _repr_object_names(self): """ EXAMPLES:: - sage: GSets(SymmetricGroup(8)) # indirect doctests + sage: GSets(SymmetricGroup(8)) # indirect doctests # optional - 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() + sage: GSets(SymmetricGroup(8)).super_categories() # optional - sage.groups [Category of sets] """ return [Sets()] @@ -67,7 +67,7 @@ def an_instance(cls): EXAMPLES:: - sage: GSets.an_instance() # indirect doctest + sage: GSets.an_instance() # indirect doctest # optional - 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 54ce5775c9e..efa1a501192 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() - sage: m.graded_algebra() is m + sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat + sage: m.graded_algebra() is m # optional - sage.combinat True """ return self diff --git a/src/sage/categories/graded_algebras_with_basis.py b/src/sage/categories/graded_algebras_with_basis.py index b4df3c3c260..52d80b78b4e 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() - sage: m.graded_algebra() is m + sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat + sage: m.graded_algebra() is m # optional - sage.combinat sage.modules True TESTS: @@ -57,21 +57,21 @@ 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() - sage: from_gr = m.from_graded_conversion() - sage: m[2] == to_gr(m[2]) == from_gr(m[2]) + 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 True - sage: u = 3*m[1] - (1/2)*m[3] - sage: u == to_gr(u) == from_gr(u) + 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 True - sage: m.zero() == to_gr(m.zero()) == from_gr(m.zero()) + sage: m.zero() == to_gr(m.zero()) == from_gr(m.zero()) # optional - sage.combinat sage.modules True - sage: p2 = m.projection(2) - sage: p2(m[2] - 4*m[1,1] + 3*m[1] - 2*m[[]]) + 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 -4*m[1, 1] + m[2] - sage: p2(4*m[1]) + sage: p2(4*m[1]) # optional - sage.combinat sage.modules 0 - sage: p2(m.zero()) == m.zero() + sage: p2(m.zero()) == m.zero() # optional - sage.combinat sage.modules True """ return self @@ -111,13 +111,13 @@ def free_graded_module(self, generator_degrees, names=None): EXAMPLES:: - 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() + 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 (g[0], g[2], g[3]) - sage: N. = Cl.free_graded_module((1, 2)) - sage: N.generators() + sage: N. = Cl.free_graded_module((1, 2)) # optional - sage.combinat sage.modules + sage: N.generators() # optional - sage.combinat sage.modules (xy, z) """ try: @@ -134,10 +134,10 @@ def formal_series_ring(self): EXAMPLES:: - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) - sage: S = NCSF.Complete() - sage: L = S.formal_series_ring() - sage: L + 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 Lazy completion of Non-Commutative Symmetric Functions over the Rational Field in the Complete basis """ @@ -185,13 +185,13 @@ def one_basis(self): EXAMPLES:: - sage: A. = ExteriorAlgebra(QQ) - sage: A.one_basis() + sage: A. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules 0 - sage: B = tensor((A, A, A)) - sage: B.one_basis() + sage: B = tensor((A, A, A)) # optional - sage.combinat sage.modules + sage: B.one_basis() # optional - sage.combinat sage.modules (0, 0, 0) - sage: B.one() + sage: B.one() # optional - sage.combinat sage.modules 1 # 1 # 1 """ # FIXME: this method should be conditionally defined, @@ -211,10 +211,10 @@ def product_on_basis(self, t0, t1): Test the sign in the super tensor product:: - sage: A = SteenrodAlgebra(3) - sage: x = A.Q(0) - sage: y = x.coproduct() - sage: y^2 + 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 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 d806597ae0c..204ab23013e 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() + sage: GradedHopfAlgebrasWithBasis(QQ).example() # optional - 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() + sage: GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - 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() - sage: H.monomial(4).counit() # indirect doctest + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules + sage: H.monomial(4).counit() # indirect doctest # optional - sage.modules 0 - sage: H.monomial(0).counit() # indirect doctest + sage: H.monomial(0).counit() # indirect doctest # optional - sage.modules 1 """ if i == self.one_basis(): @@ -144,14 +144,14 @@ def antipode_on_basis(self, index): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() - sage: H.monomial(0).antipode() # indirect doctest + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules + sage: H.monomial(0).antipode() # indirect doctest # optional - sage.modules P0 - sage: H.monomial(1).antipode() # indirect doctest + sage: H.monomial(1).antipode() # indirect doctest # optional - sage.modules -P1 - sage: H.monomial(2).antipode() # indirect doctest + sage: H.monomial(2).antipode() # indirect doctest # optional - sage.modules P2 - sage: H.monomial(3).antipode() # indirect doctest + sage: H.monomial(3).antipode() # indirect doctest # optional - sage.modules -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 66950ecce53..2650492898d 100644 --- a/src/sage/categories/graded_lie_conformal_algebras.py +++ b/src/sage/categories/graded_lie_conformal_algebras.py @@ -31,11 +31,11 @@ def Super(self, base_ring=None): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) - sage: C.Graded().Super() is C.Super().Graded() + sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field + sage: C.Graded().Super() is C.Super().Graded() # optional - sage.rings.number_field True - sage: Cp = C.WithBasis() - sage: Cp.Graded().Super() is Cp.Super().Graded() + sage: Cp = C.WithBasis() # optional - sage.rings.number_field + sage: Cp.Graded().Super() is Cp.Super().Graded() # optional - sage.rings.number_field True """ return self.base_category().Super(base_ring).Graded() @@ -46,10 +46,10 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).Graded() + sage: LieConformalAlgebras(QQbar).Graded() # optional - sage.rings.number_field Category of H-graded Lie conformal algebras over Algebraic Field - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - 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 +60,7 @@ class GradedLieConformalAlgebras(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).Graded(); C + sage: C = LieConformalAlgebras(QQbar).Graded(); C # optional - 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 1868147bedb..b1185e20352 100644 --- a/src/sage/categories/graded_modules_with_basis.py +++ b/src/sage/categories/graded_modules_with_basis.py @@ -46,17 +46,18 @@ def degree_negation(self, element): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: E.degree_negation((1 + a) * (1 + b)) + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: E.degree_negation((1 + a) * (1 + b)) # optional - sage.combinat sage.modules a*b - a - b + 1 - sage: E.degree_negation(E.zero()) + sage: E.degree_negation(E.zero()) # optional - sage.combinat sage.modules 0 - sage: P = GradedModulesWithBasis(ZZ).example(); P - 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))] - sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) - sage: P.degree_negation(p) + sage: P = GradedModulesWithBasis(ZZ).example(); P # optional - 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 -4*P[1] - 2*P[2] + P[3, 1] """ base_one = self.base_ring().one() @@ -114,56 +115,63 @@ 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) - 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() + 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 + 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 1 - sage: S.basis()[1].degree() + sage: S.basis()[1].degree() # optional - sage.combinat sage.modules 2 We check on the echelonized basis:: - sage: Sp = E.submodule([1, x + y + 5, x*y - y*z + x + y - 2]) - sage: Sp.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: 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 + 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 If it is generated by inhomogeneous elements, then it is filtered by default:: - sage: F = E.submodule([x + y*z, x*z + y*x]) - sage: F.category() - 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 Category of finite dimensional vector spaces with basis over Rational Field + sage: F = E.submodule([x + y*z, x*z + y*x]) # optional - sage.combinat sage.modules + sage: F.category() # optional - 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 + Category of finite dimensional vector spaces with basis over Rational Field If ``category`` is specified, then it does not give any extra structure to the submodule (we can think of this as applying the forgetful functor):: - sage: SM = E.submodule([x + y, x*y - y*z], category=ModulesWithBasis(QQ)) - 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], category=ModulesWithBasis(QQ)) - sage: FM.category() - Join of Category of finite dimensional vector spaces with basis over Rational Field - and Category of subobjects of sets + sage: SM = E.submodule([x + y, x*y - y*z], # optional - sage.combinat sage.modules + ....: category=ModulesWithBasis(QQ)) + sage: SM.category() # optional - sage.combinat sage.modules + 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 + ....: category=ModulesWithBasis(QQ)) + sage: FM.category() # optional - sage.combinat sage.modules + Join of + Category of finite dimensional vector spaces with basis over Rational Field and + Category of subobjects of sets If we have specified that this is a graded submodule of a graded module, then the echelonized elements must be homogeneous:: sage: Cat = ModulesWithBasis(QQ).Graded().Subobjects() - sage: E.submodule([x + y, x*y - 1], category=Cat) + sage: E.submodule([x + y, x*y - 1], category=Cat) # optional - 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) + sage: E.submodule([x + y, x*y - x - y], category=Cat) # optional - sage.combinat sage.modules Free module generated by {0, 1} over Rational Field """ # Make sure gens consists of elements of ``self`` @@ -215,13 +223,14 @@ def quotient_module(self, submodule, check=True, already_echelonized=False, cate EXAMPLES:: - 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 Category of finite dimensional vector spaces with basis over Rational Field + 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 + 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 + Category of finite dimensional vector spaces with basis over Rational Field .. SEEALSO:: @@ -258,17 +267,18 @@ def degree_negation(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: ((1 + a) * (1 + b)).degree_negation() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: ((1 + a) * (1 + b)).degree_negation() # optional - sage.combinat sage.modules a*b - a - b + 1 - sage: E.zero().degree_negation() + sage: E.zero().degree_negation() # optional - sage.combinat sage.modules 0 - sage: P = GradedModulesWithBasis(ZZ).example(); P - 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))] - sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) - sage: p.degree_negation() + sage: P = GradedModulesWithBasis(ZZ).example(); P # optional - 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 -4*P[1] - 2*P[2] + P[3, 1] """ return self.parent().degree_negation(self) @@ -282,13 +292,13 @@ def degree_on_basis(self, m): EXAMPLES:: - 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()] + 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 [1, z, x*z, y*z, x*y*z] - sage: [Q.degree_on_basis(i) for i in Q.indices()] + sage: [Q.degree_on_basis(i) for i in Q.indices()] # optional - sage.combinat sage.modules [0, 1, 2, 2, 3] """ return self.basis()[m].lift().degree() @@ -300,13 +310,13 @@ def degree(self): EXAMPLES:: - 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()] + 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 [1, z, x*z, y*z, x*y*z] - sage: [B[i].degree() for i in Q.indices()] + sage: [B[i].degree() for i in Q.indices()] # optional - sage.combinat sage.modules [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 0df6bf44165..46e36fd47cf 100644 --- a/src/sage/categories/group_algebras.py +++ b/src/sage/categories/group_algebras.py @@ -50,15 +50,16 @@ class GroupAlgebras(AlgebrasCategory): Here is how to create the group algebra of a group `G`:: - sage: G = DihedralGroup(5) - sage: QG = G.algebra(QQ); QG - Algebra of Dihedral group of order 10 as a permutation group over Rational Field + sage: G = DihedralGroup(5) # optional - sage.groups + sage: QG = G.algebra(QQ); QG # optional - 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 + sage: g = G.an_element(); g # optional - sage.groups sage.modules (1,4)(2,3) - sage: (QG.term(g) + 1)**3 + sage: (QG.term(g) + 1)**3 # optional - sage.groups sage.modules 4*() + 4*(1,4)(2,3) .. TODO:: @@ -68,14 +69,14 @@ class GroupAlgebras(AlgebrasCategory): TESTS:: - sage: A = GroupAlgebras(QQ).example(GL(3, GF(11))) - sage: A.one_basis() + 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 [1 0 0] [0 1 0] [0 0 1] - sage: A = SymmetricGroupAlgebra(QQ,4) - sage: x = Permutation([4,3,2,1]) - sage: A.product_on_basis(x,x) + 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 [1, 2, 3, 4] sage: C = GroupAlgebras(ZZ) @@ -104,13 +105,15 @@ def example(self, G=None): EXAMPLES:: - sage: GroupAlgebras(QQ['x']).example() - Algebra of Dihedral group of order 8 as a permutation group over Univariate Polynomial Ring in x over Rational Field + sage: GroupAlgebras(QQ['x']).example() # optional - 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)) - Algebra of Alternating group of order 4!/2 as a permutation group over Rational Field + sage: GroupAlgebras(QQ).example(AlternatingGroup(4)) # optional - sage.groups sage.modules + Algebra of + Alternating group of order 4!/2 as a permutation group over Rational Field """ from sage.groups.perm_gps.permgroup_named import DihedralGroup if G is None: @@ -124,19 +127,19 @@ def __init_extra__(self): EXAMPLES:: - sage: A = GroupAlgebra(SymmetricGroup(4), QQ) - sage: B = GroupAlgebra(SymmetricGroup(3), ZZ) - sage: A.has_coerce_map_from(B) + 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 True - sage: B.has_coerce_map_from(A) + sage: B.has_coerce_map_from(A) # optional - sage.groups sage.modules False - sage: A.has_coerce_map_from(ZZ) + sage: A.has_coerce_map_from(ZZ) # optional - sage.groups sage.modules True - sage: A.has_coerce_map_from(CC) + sage: A.has_coerce_map_from(CC) # optional - sage.groups sage.modules False - sage: A.has_coerce_map_from(SymmetricGroup(5)) + sage: A.has_coerce_map_from(SymmetricGroup(5)) # optional - sage.groups sage.modules False - sage: A.has_coerce_map_from(SymmetricGroup(2)) + sage: A.has_coerce_map_from(SymmetricGroup(2)) # optional - sage.groups sage.modules True """ if not self.base_ring().has_coerce_map_from(self.group()): @@ -152,8 +155,8 @@ def _latex_(self): EXAMPLES:: - sage: A = GroupAlgebra(KleinFourGroup(), ZZ) - sage: latex(A) # indirect doctest + sage: A = GroupAlgebra(KleinFourGroup(), ZZ) # optional - sage.groups sage.modules + sage: latex(A) # indirect doctest # optional - sage.groups sage.modules \Bold{Z}[\langle (3,4), (1,2) \rangle] """ from sage.misc.latex import latex @@ -165,9 +168,9 @@ def group(self): EXAMPLES:: - sage: GroupAlgebras(QQ).example(GL(3, GF(11))).group() + sage: GroupAlgebras(QQ).example(GL(3, GF(11))).group() # optional - sage.groups sage.modules sage.rings.finite_rings General Linear Group of degree 3 over Finite Field of size 11 - sage: SymmetricGroup(10).algebra(QQ).group() + sage: SymmetricGroup(10).algebra(QQ).group() # optional - sage.groups sage.modules Symmetric group of order 10! as a permutation group """ return self.basis().keys() @@ -195,7 +198,7 @@ def center_basis(self): EXAMPLES:: - sage: SymmetricGroup(3).algebra(QQ).center_basis() + sage: SymmetricGroup(3).algebra(QQ).center_basis() # optional - sage.groups sage.modules ((), (2,3) + (1,2) + (1,3), (1,2,3) + (1,3,2)) .. SEEALSO:: @@ -217,15 +220,16 @@ def coproduct_on_basis(self, g): EXAMPLES:: - 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 + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - 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 (1,2,3,4,5,6) - sage: A.coproduct_on_basis(g) + sage: A.coproduct_on_basis(g) # optional - sage.groups sage.modules (1,2,3,4,5,6) # (1,2,3,4,5,6) - sage: a = A.an_element(); a + sage: a = A.an_element(); a # optional - sage.groups sage.modules () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.coproduct() + sage: a.coproduct() # optional - sage.groups sage.modules () # () + 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 @@ -242,15 +246,16 @@ def antipode_on_basis(self,g): EXAMPLES:: - 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 + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - 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 (1,2,3,4,5,6) - sage: A.antipode_on_basis(g) + sage: A.antipode_on_basis(g) # optional - sage.groups sage.modules (1,6,5,4,3,2) - sage: a = A.an_element(); a + sage: a = A.an_element(); a # optional - sage.groups sage.modules () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.antipode() + sage: a.antipode() # optional - sage.groups sage.modules () + 3*(1,5,3)(2,6,4) + 3*(1,6,5,4,3,2) """ return self.term(~g) @@ -265,11 +270,12 @@ def counit_on_basis(self,g): EXAMPLES:: - 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 + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - 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 (1,2,3,4,5,6) - sage: A.counit_on_basis(g) + sage: A.counit_on_basis(g) # optional - sage.groups sage.modules 1 """ return self.base_ring().one() @@ -284,11 +290,12 @@ def counit(self,x): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A - Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: a = A.an_element(); a + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - 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 () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.counit() + sage: a.counit() # optional - sage.groups sage.modules 7 """ return self.base_ring().sum(x.coefficients()) @@ -305,17 +312,19 @@ def is_integral_domain(self, proof=True): EXAMPLES:: - sage: GroupAlgebra(SymmetricGroup(2)).is_integral_domain() + sage: S2 = SymmetricGroup(2) # optional - sage.groups + sage: GroupAlgebra(S2).is_integral_domain() # optional - sage.groups sage.modules False - sage: GroupAlgebra(SymmetricGroup(1)).is_integral_domain() + sage: S1 = SymmetricGroup(1) + sage: GroupAlgebra(S1).is_integral_domain() # optional - sage.groups sage.modules True - sage: GroupAlgebra(SymmetricGroup(1), IntegerModRing(4)).is_integral_domain() + sage: GroupAlgebra(S1, IntegerModRing(4)).is_integral_domain() # optional - sage.groups sage.modules False - sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain() + sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain() # optional - sage.groups sage.modules True - sage: GroupAlgebra(AbelianGroup(2, [0,2])).is_integral_domain() + sage: GroupAlgebra(AbelianGroup(2, [0,2])).is_integral_domain() # optional - sage.groups sage.modules False - sage: GroupAlgebra(GL(2, ZZ)).is_integral_domain() # not implemented + sage: GroupAlgebra(GL(2, ZZ)).is_integral_domain() # not implemented # optional - sage.groups sage.modules False """ from sage.sets.set import Set @@ -385,22 +394,24 @@ def central_form(self): EXAMPLES:: - sage: QS3 = SymmetricGroup(3).algebra(QQ) - sage: A = QS3([2,3,1]) + QS3([3,1,2]) - sage: A.central_form() + 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 B[(1,2,3)] - sage: QS4 = SymmetricGroup(4).algebra(QQ) - sage: B = sum(len(s.cycle_type())*QS4(s) for s in Permutations(4)) - sage: B.central_form() + 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 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: QG = GroupAlgebras(QQ).example(PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])) - sage: s = sum(i for i in 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)] + 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(i for i in QG.basis()) # optional - sage.groups sage.modules + sage: s.central_form() # not tested # optional - sage.groups sage.modules + 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)] .. SEEALSO:: diff --git a/src/sage/categories/groupoid.py b/src/sage/categories/groupoid.py index 4c6e3ae6042..9eee3750655 100644 --- a/src/sage/categories/groupoid.py +++ b/src/sage/categories/groupoid.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.groups r""" Groupoid """ diff --git a/src/sage/categories/groups.py b/src/sage/categories/groups.py index 97d57799f8c..569cfc0d36d 100644 --- a/src/sage/categories/groups.py +++ b/src/sage/categories/groups.py @@ -42,7 +42,7 @@ def example(self): """ EXAMPLES:: - sage: Groups().example() + sage: Groups().example() # optional - sage.groups General Linear Group of degree 4 over Rational Field """ from sage.rings.rational_field import QQ @@ -69,13 +69,13 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Groups.free(index_set=ZZ) + sage: Groups.free(index_set=ZZ) # optional - sage.groups Free group indexed by Integer Ring - sage: Groups().free(ZZ) + sage: Groups().free(ZZ) # optional - sage.groups Free group indexed by Integer Ring - sage: Groups().free(5) + sage: Groups().free(5) # optional - sage.groups Free Group on generators {x0, x1, x2, x3, x4} - sage: F. = Groups().free(); F + sage: F. = Groups().free(); F # optional - sage.groups Free Group on generators {x, y, z} """ from sage.rings.integer_ring import ZZ @@ -99,8 +99,8 @@ def group_generators(self): EXAMPLES:: - sage: A = AlternatingGroup(4) - sage: A.group_generators() + sage: A = AlternatingGroup(4) # optional - sage.groups + sage: A.group_generators() # optional - sage.groups Family ((2,3,4), (1,2,3)) """ from sage.sets.family import Family @@ -120,11 +120,11 @@ def monoid_generators(self): EXAMPLES:: - sage: A = AlternatingGroup(4) - sage: A.monoid_generators() + sage: A = AlternatingGroup(4) # optional - sage.groups + sage: A.monoid_generators() # optional - sage.groups Family ((2,3,4), (1,2,3)) - sage: F. = FreeGroup() - sage: F.monoid_generators() + sage: F. = FreeGroup() # optional - sage.groups + sage: F.monoid_generators() # optional - sage.groups Family (x, y, x^-1, y^-1) """ G = self.group_generators() @@ -142,8 +142,8 @@ def _test_inverse(self, **options): EXAMPLES:: - sage: G = SymmetricGroup(3) - sage: G._test_inverse() + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: G._test_inverse() # optional - sage.groups """ tester = self._tester(**options) for x in tester.some_elements(): @@ -156,11 +156,13 @@ def semidirect_product(self, N, mapping, check=True): EXAMPLES:: - sage: G = Groups().example() - sage: G.semidirect_product(G,Morphism(G,G)) + sage: G = Groups().example() # optional - sage.groups + sage: G.semidirect_product(G, Morphism(G, G)) # optional - sage.groups Traceback (most recent call last): ... - NotImplementedError: semidirect product of General Linear Group of degree 4 over Rational Field and General Linear Group of degree 4 over Rational Field not yet implemented + NotImplementedError: semidirect product of General Linear Group of degree 4 + over Rational Field and General Linear Group of degree 4 over Rational Field + not yet implemented """ raise NotImplementedError("semidirect product of %s and %s not yet implemented" % (self, N)) @@ -176,11 +178,12 @@ def holomorph(self): EXAMPLES:: - sage: G = Groups().example() - sage: G.holomorph() + sage: G = Groups().example() # optional - sage.groups + sage: G.holomorph() # optional - sage.groups Traceback (most recent call last): ... - NotImplementedError: holomorph of General Linear Group of degree 4 over Rational Field not yet implemented + NotImplementedError: holomorph of General Linear Group of degree 4 + over Rational Field not yet implemented """ raise NotImplementedError("holomorph of %s not yet implemented"%self) @@ -243,11 +246,11 @@ 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) - sage: T = G.cayley_table() - sage: T.column_keys() + sage: G = DiCyclicGroup(3) # optional - sage.groups + sage: T = G.cayley_table() # optional - sage.groups + sage: T.column_keys() # optional - sage.groups ((), (5,6,7), ..., (1,4,2,3)(5,7)) - sage: T + sage: T # optional - sage.groups * 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 @@ -265,8 +268,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: M = SL(2, 2) - sage: M.cayley_table() + sage: M = SL(2, 2) # optional - sage.groups + sage: M.cayley_table() # optional - sage.groups * a b c d e f +------------ a| a b c d e f @@ -279,8 +282,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: A = AbelianGroup([2, 3]) - sage: A.cayley_table() + sage: A = AbelianGroup([2, 3]) # optional - sage.groups + sage: A.cayley_table() # optional - sage.groups * a b c d e f +------------ a| a b c d e f @@ -298,8 +301,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) - sage: C.cayley_table(names='digits') + sage: C = CyclicPermutationGroup(11) # optional - sage.groups + sage: C.cayley_table(names='digits') # optional - 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 @@ -316,9 +319,9 @@ def cayley_table(self, names='letters', elements=None): :: - sage: G = QuaternionGroup() - sage: names = ['1', 'I', '-1', '-I', 'J', '-K', '-J', 'K'] - sage: G.cayley_table(names=names) + 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 * 1 I -1 -I J -K -J K +------------------------ 1| 1 I -1 -I J -K -J K @@ -332,8 +335,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: A = AbelianGroup([2,2]) - sage: A.cayley_table(names='elements') + sage: A = AbelianGroup([2, 2]) # optional - sage.groups + sage: A.cayley_table(names='elements') # optional - sage.groups * 1 f1 f0 f0*f1 +------------------------ 1| 1 f1 f0 f0*f1 @@ -345,10 +348,10 @@ def cayley_table(self, names='letters', elements=None): routine behaves similarly, but changes an existing table "in-place." :: - sage: G = AlternatingGroup(3) - sage: T = G.cayley_table() - sage: T.change_names('digits') - sage: T + 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 * 0 1 2 +------ 0| 0 1 2 @@ -360,11 +363,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) - sage: G + sage: G = SL(2,ZZ) # optional - sage.groups + sage: G # optional - sage.groups Special Linear Group of degree 2 over Integer Ring - sage: identity = matrix(ZZ, [[1,0], [0,1]]) - sage: G.cayley_table(elements=[identity, -identity]) + sage: identity = matrix(ZZ, [[1,0], [0,1]]) # optional - sage.groups + sage: G.cayley_table(elements=[identity, -identity]) # optional - sage.groups * a b +---- a| a b @@ -381,11 +384,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 - sage: G = DiCyclicGroup(3) - sage: commutator = lambda x, y: x*y*x^-1*y^-1 - sage: T = OperationTable(G, commutator) - sage: T + 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 . 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 @@ -401,12 +404,12 @@ class provides even greater flexibility, including changing 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() - sage: comm = [trans['a'], trans['b'], trans['c']] - sage: comm + sage: trans = T.translation() # optional - sage.groups + sage: comm = [trans['a'], trans['b'], trans['c']] # optional - sage.groups + sage: comm # optional - sage.groups [(), (5,6,7), (5,7,6)] - sage: P = G.cayley_table(elements=comm) - sage: P + sage: P = G.cayley_table(elements=comm) # optional - sage.groups + sage: P # optional - sage.groups * a b c +------ a| a b c @@ -437,9 +440,9 @@ def conjugacy_class(self, g): EXAMPLES:: - sage: A = AbelianGroup([2,2]) - sage: c = A.conjugacy_class(A.an_element()) - sage: type(c) + 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 """ from sage.groups.conjugacy_classes import ConjugacyClass @@ -452,29 +455,32 @@ def conjugacy_class(self): EXAMPLES:: - sage: D = DihedralGroup(5) - sage: g = D((1,3,5,2,4)) - sage: g.conjugacy_class() - Conjugacy class of (1,3,5,2,4) in Dihedral group of order 10 as a permutation group + 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 + 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]), matrix(GF(5),2, [1,1, 0,1])]) - sage: h = H(matrix(GF(5),2,[1,2, -1, 1])) - sage: h.conjugacy_class() + sage: H = MatrixGroup([matrix(GF(5), 2, [1,2, -1,1]), # optional - sage.groups sage.rings.finite_rings 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 Conjugacy class of [1 2] - [4 1] in Matrix group over Finite Field of size 5 with 2 generators ( + [4 1] + in Matrix group over Finite Field of size 5 with 2 generators ( [1 2] [1 1] [4 1], [0 1] ) - sage: G = SL(2, GF(2)) - sage: g = G.gens()[0] - sage: g.conjugacy_class() + 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 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) - sage: g = G([[1,1],[0,1]]) - sage: g.conjugacy_class() + 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 Conjugacy class of [1 1] [0 1] in Special Linear Group of degree 2 over Rational Field """ @@ -505,13 +511,13 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Groups.Commutative.free(index_set=ZZ) + sage: Groups.Commutative.free(index_set=ZZ) # optional - sage.groups Free abelian group indexed by Integer Ring - sage: Groups().Commutative().free(ZZ) + sage: Groups().Commutative().free(ZZ) # optional - sage.groups Free abelian group indexed by Integer Ring - sage: Groups().Commutative().free(5) + sage: Groups().Commutative().free(5) # optional - sage.groups Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z - sage: F. = Groups().Commutative().free(); F + sage: F. = Groups().Commutative().free(); F # optional - sage.groups Multiplicative Abelian group isomorphic to Z x Z x Z """ from sage.rings.integer_ring import ZZ @@ -568,11 +574,11 @@ def group_generators(self): EXAMPLES:: - sage: C5 = CyclicPermutationGroup(5) - sage: C4 = CyclicPermutationGroup(4) - sage: S4 = SymmetricGroup(3) - sage: C = cartesian_product([C5, C4, S4]) - sage: C.group_generators() + 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 Family (((1,2,3,4,5), (), ()), ((), (1,2,3,4), ()), ((), (), (1,2)), @@ -580,16 +586,16 @@ def group_generators(self): We check the other portion of :trac:`16718` is fixed:: - sage: len(C.j_classes()) + sage: len(C.j_classes()) # optional - sage.groups 1 An example with an infinitely generated group (a better output is needed):: - sage: G = Groups.free([1,2]) - sage: H = Groups.free(ZZ) - sage: C = cartesian_product([G, H]) - sage: C.monoid_generators() + 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 Lazy family (gen(i))_{i in The Cartesian product of (...)} """ F = self.cartesian_factors() @@ -622,13 +628,13 @@ def order(self): EXAMPLES:: - sage: C = cartesian_product([SymmetricGroup(10), SL(2,GF(3))]) - sage: C.order() + 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 87091200 TESTS:: - sage: C.order.__module__ + sage: C.order.__module__ # optional - 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 6b593d4fb3a..9372e88c54b 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)) + sage: HeckeModules(FiniteField(5)) # optional - sage.rings.finite_rings 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() + sage: HeckeModules(Partitions(3)).run() # optional - sage.combinat Traceback (most recent call last): ... TypeError: R (=Partitions of the integer 3) must be a commutative ring @@ -123,7 +123,10 @@ def _Hom_(self, Y, category): 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 + 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__ sage: TestSuite(H).run(skip=["_test_elements", "_test_an_element", "_test_elements_eq", @@ -142,7 +145,8 @@ def _Hom_(self, Y, category): sage: H = M._Hom_(M, category = HeckeModules(GF(5))); H Traceback (most recent call last): ... - TypeError: Category of Hecke modules over Finite Field of size 5 is not a subcategory of Category of Hecke modules over Rational Field + TypeError: Category of Hecke modules over Finite Field of size 5 + is not a subcategory of Category of Hecke modules over Rational Field """ # TODO: double check that it's the correct HeckeModules category below: if category is not None and not category.is_subcategory(HeckeModules(self.base_ring())): diff --git a/src/sage/categories/highest_weight_crystals.py b/src/sage/categories/highest_weight_crystals.py index b8afdee2117..226d310eb35 100644 --- a/src/sage/categories/highest_weight_crystals.py +++ b/src/sage/categories/highest_weight_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs, sage.combinat r""" Highest Weight Crystals """ @@ -128,7 +129,8 @@ def highest_weight_vectors(self): :: sage: C = crystals.Letters(['A',2]) - sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)],[C(1),C(2),C(1)]]) + sage: T = crystals.TensorProduct(C, C, C, generators=[[C(2),C(1),C(1)], + ....: [C(1),C(2),C(1)]]) sage: T.highest_weight_vectors() ([2, 1, 1], [1, 2, 1]) """ @@ -174,7 +176,8 @@ def lowest_weight_vectors(self): :: sage: C = crystals.Letters(['A',2]) - sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)],[C(1),C(2),C(1)]]) + sage: T = crystals.TensorProduct(C, C, C,generators=[[C(2),C(1),C(1)], + ....: [C(1),C(2),C(1)]]) sage: T.lowest_weight_vectors() ([3, 2, 3], [3, 3, 2]) """ diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index 88b162c5845..6554c895ff4 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -11,26 +11,26 @@ In the following, the :class:`Hom` object is indeed cached:: - sage: K = GF(17) - sage: H = Hom(ZZ, K) - sage: H + 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 Set of Homomorphisms from Integer Ring to Finite Field of size 17 - sage: H is Hom(ZZ, K) + sage: H is Hom(ZZ, K) # optional - sage.rings.finite_rings True Nonetheless, garbage collection occurs when the original references are overwritten:: - sage: for p in prime_range(200): + sage: for p in prime_range(200): # optional - sage.rings.finite_rings ....: 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 - sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] - sage: len(L) + 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 1 - sage: L + sage: L # optional - sage.rings.finite_rings [Finite Field of size 199] AUTHORS: @@ -104,34 +104,43 @@ def Hom(X, Y, category=None, check=True): EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: Hom(V, V) + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: Hom(V, V) # optional - 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) - sage: Hom(G, G) - 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()) + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: Hom(G, G) # optional - 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 Set of Morphisms from Integer Ring to Rational Field in Category of sets - sage: Hom(FreeModule(ZZ,1), FreeModule(QQ,1)) - 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)) - 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 in Category of commutative additive groups + sage: Hom(FreeModule(ZZ, 1), FreeModule(QQ, 1)) # optional - 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 + 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 + in Category of commutative additive groups 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): + sage: for p in prime_range(10^3): # optional - sage.rings.finite_rings ....: 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 - sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] - sage: len(L), L[0] + 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 (1, Finite Field of size 997) To illustrate the choice of the category, we consider the @@ -139,13 +148,13 @@ def Hom(X, Y, category=None, check=True): sage: X = ZZ; X Integer Ring - sage: Y = SymmetricGroup(3); Y + sage: Y = SymmetricGroup(3); Y # optional - 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) + sage: Hom(X, Y) # optional - sage.groups Set of Morphisms from Integer Ring to Symmetric group of order 3! as a permutation group in Category of enumerated monoids @@ -153,10 +162,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()) - Set of Morphisms from Integer Ring to Symmetric group of order 3! as a permutation group in Category of magmas + sage: Hom(X, Y, Magmas()) # optional - 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()) + sage: Hom(X, Y, Groups()) # optional - sage.groups Traceback (most recent call last): ... ValueError: Integer Ring is not in Category of groups @@ -183,10 +195,10 @@ def Hom(X, Y, category=None, check=True): Homset are unique parents:: - sage: k = GF(5) - sage: H1 = Hom(k,k) - sage: H2 = Hom(k,k) - sage: H1 is H2 + 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 True Moreover, if no category is provided, then the result is identical @@ -231,16 +243,16 @@ def Hom(X, Y, category=None, check=True): Variation on the theme:: - sage: U1 = FreeModule(ZZ,2) - sage: U2 = FreeModule(ZZ,2,inner_product_matrix=matrix([[1,0],[0,-1]])) - sage: U1 == U2, U1 is U2 + 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 (False, False) - sage: V = ZZ^3 - sage: H1 = Hom(U1, V); H2 = Hom(U2, V) - sage: H1 == H2, H1 is H2 + 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 (False, False) - sage: H1 = Hom(V, U1); H2 = Hom(V, U2) - sage: H1 == H2, H1 is H2 + sage: H1 = Hom(V, U1); H2 = Hom(V, U2) # optional - sage.modules + sage: H1 == H2, H1 is H2 # optional - sage.modules (False, False) Since :trac:`11900`, the meet of the categories of the given arguments is @@ -249,12 +261,18 @@ def Hom(X, Y, category=None, check=True): sage: PA = Parent(category=Algebras(QQ)) sage: PJ = Parent(category=Rings() & Modules(QQ)) - sage: Hom(PA,PJ) - Set of Homomorphisms from to - sage: Hom(PA,PJ).category() - Category of homsets of unital magmas and right modules over Rational Field and left modules over Rational Field - sage: Hom(PA,PJ, Rngs()) - Set of Morphisms from to in Category of rngs + sage: Hom(PA, PJ) + Set of Homomorphisms + from + to + sage: Hom(PA, PJ).category() + Category of homsets of + unital magmas and right modules over Rational Field + and left modules over Rational Field + sage: Hom(PA, PJ, Rngs()) + Set of Morphisms + from + to in Category of rngs .. TODO:: @@ -280,17 +298,17 @@ 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") - sage: Hom(S, S, SimplicialComplexes()) + sage: S = SimplicialComplex([[1,2], [1,4]]); S.rename("S") # optional - sage.graphs + sage: Hom(S, S, SimplicialComplexes()) # optional - sage.graphs Set of Morphisms from S to S in Category of finite simplicial complexes - sage: Hom(Set(), S, Sets()) + sage: Hom(Set(), S, Sets()) # optional - sage.graphs Set of Morphisms from {} to S in Category of sets - sage: Hom(S, Set(), Sets()) + sage: Hom(S, Set(), Sets()) # optional - sage.graphs Set of Morphisms from S to {} in Category of sets - sage: H = Hom(S, S, ChainComplexes(QQ)) + sage: H = Hom(S, S, ChainComplexes(QQ)) # optional - sage.graphs Traceback (most recent call last): ... ValueError: S is not in Category of chain complexes over Rational Field @@ -303,11 +321,11 @@ def Hom(X, Y, category=None, check=True): ....: 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) + sage: S.category().is_subcategory(C) # optional - sage.graphs False - sage: S in C + sage: S in C # optional - sage.graphs True - sage: Hom(S, S, C) + sage: Hom(S, S, C) # optional - sage.graphs Set of Morphisms from S to S in Permissive category With ``check=False``, uninitialized parents, as can appear upon @@ -331,16 +349,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]) - sage: q = Q.an_element() - sage: explain_pickle(dumps(Q)) + 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 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)) + sage: Q == loads(dumps(Q)) # optional - sage.libs.singular True Check that the ``_Hom_`` method of the ``category`` input is used:: @@ -486,21 +504,24 @@ def End(X, category=None): EXAMPLES:: - sage: V = VectorSpace(QQ, 3) - sage: End(V) - Set of Morphisms (Linear Transformations) from - Vector space of dimension 3 over Rational Field to - Vector space of dimension 3 over Rational Field + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: End(V) # optional - 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) - 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: G = AlternatingGroup(3) # optional - sage.groups + sage: S = End(G); S # optional - 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: from sage.categories.homset import is_Endset - sage: is_Endset(S) + sage: is_Endset(S) # optional - sage.groups True - sage: S.domain() + sage: S.domain() # optional - sage.groups Alternating group of order 3!/2 as a permutation group To avoid creating superfluous categories, a homset in a category @@ -512,13 +533,13 @@ def End(X, category=None): groups currently implement nothing more than unital magmas about their homsets, we have:: - sage: G = GL(3,3) - sage: G.category() + sage: G = GL(3, 3) # optional - sage.groups + sage: G.category() # optional - sage.groups Category of finite groups - sage: H = Hom(G,G) - sage: H.homset_category() + sage: H = Hom(G, G) # optional - sage.groups + sage: H.homset_category() # optional - sage.groups Category of finite groups - sage: H.category() + sage: H.category() # optional - sage.groups Category of endsets of unital magmas Similarly, a ring morphism just needs to preserve addition, @@ -557,8 +578,8 @@ class Homset(Set_generic): EXAMPLES:: - sage: H = Hom(QQ^2, QQ^3) - sage: loads(H.dumps()) is H + sage: H = Hom(QQ^2, QQ^3) # optional - sage.modules + sage: loads(H.dumps()) is H # optional - sage.modules True Homsets of unique parents are unique as well:: @@ -571,10 +592,11 @@ class Homset(Set_generic): Conversely, homsets of non-unique parents are non-unique:: - sage: H = End(ProductProjectiveSpaces(QQ, [1, 1])) - sage: loads(dumps(ProductProjectiveSpaces(QQ, [1, 1]))) is ProductProjectiveSpaces(QQ, [1, 1]) + sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) + sage: H = End(P11) + sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) False - sage: loads(dumps(ProductProjectiveSpaces(QQ, [1, 1]))) == ProductProjectiveSpaces(QQ, [1, 1]) + sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) True sage: loads(dumps(H)) is H False @@ -621,12 +643,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() + sage: Hom(QQ^3, QQ^3, category=Modules(QQ)).base_ring() # optional - sage.modules Rational Field For whatever it's worth, the ``base`` arguments takes precedence:: - sage: MyHomset(ZZ^3, ZZ^3, base = QQ).base_ring() + sage: MyHomset(ZZ^3, ZZ^3, base=QQ).base_ring() # optional - sage.modules Rational Field """ self._domain = X @@ -679,8 +701,8 @@ def __reduce__(self): EXAMPLES:: - sage: H = Hom(QQ^2, QQ^3) - sage: H.__reduce__() + sage: H = Hom(QQ^2, QQ^3) # optional - sage.modules + sage: H.__reduce__() # optional - sage.modules (, (Vector space of dimension 2 over Rational Field, Vector space of dimension 3 over Rational Field, @@ -690,18 +712,18 @@ def __reduce__(self): TESTS:: - sage: loads(H.dumps()) is H + sage: loads(H.dumps()) is H # optional - sage.modules True Homsets of non-unique parents are non-unique as well:: - sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) - sage: G is loads(dumps(G)) + sage: G = PermutationGroup([[(1, 2, 3), (4, 5)], [(3, 4)]]) # optional - sage.groups + sage: G is loads(dumps(G)) # optional - sage.groups False - sage: H = Hom(G,G) - sage: H is loads(dumps(H)) + sage: H = Hom(G, G) # optional - sage.groups + sage: H is loads(dumps(H)) # optional - sage.groups False - sage: H == loads(dumps(H)) + sage: H == loads(dumps(H)) # optional - sage.groups True """ return Hom, (self._domain, self._codomain, self.__category, False) @@ -710,7 +732,7 @@ def _repr_(self): """ TESTS:: - sage: Hom(ZZ^2, QQ, category=Sets())._repr_() + sage: Hom(ZZ^2, QQ, category=Sets())._repr_() # optional - 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, @@ -727,10 +749,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') # optional - sage.symbolic + sage: H = E(0).parent(); H # optional - sage.symbolic 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())) + sage: hash(H) == hash((H.domain(), H.codomain(), H.base())) # optional - sage.symbolic True """ return hash((self._domain, self._codomain, self.base())) @@ -751,8 +773,8 @@ def homset_category(self): EXAMPLES:: - sage: H = Hom(AlternatingGroup(4), AlternatingGroup(7)) - sage: H.homset_category() + sage: H = Hom(AlternatingGroup(4), AlternatingGroup(7)) # optional - sage.groups + sage: H.homset_category() # optional - sage.groups Category of finite enumerated permutation groups """ return self.__category @@ -763,9 +785,9 @@ def _element_constructor_(self, x, check=None, **options): EXAMPLES:: - sage: H = Hom(SymmetricGroup(4), SymmetricGroup(7)) - sage: phi = Hom(SymmetricGroup(5), SymmetricGroup(6)).natural_map() - sage: phi + 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 Coercion morphism: From: Symmetric group of order 5! as a permutation group To: Symmetric group of order 6! as a permutation group @@ -777,7 +799,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) + sage: H(phi) # optional - sage.groups Composite map: From: Symmetric group of order 4! as a permutation group To: Symmetric group of order 7! as a permutation group @@ -798,7 +820,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)) + sage: copy(H(phi)) # optional - sage.groups Composite map: From: Symmetric group of order 4! as a permutation group To: Symmetric group of order 7! as a permutation group @@ -825,7 +847,7 @@ def _element_constructor_(self, x, check=None, **options): (2, 3, 4) sage: H = Hom(Set([1,2,3]), Set([1,2,3])) - sage: f = H( lambda x: 4-x ) + sage: f = H(lambda x: 4 - x) sage: f.parent() Set of Morphisms from {1, 2, 3} to {1, 2, 3} in Category of finite enumerated sets sage: f(1), f(2), f(3) # todo: not implemented @@ -884,24 +906,24 @@ def _element_constructor_(self, x, check=None, **options): TESTS:: - sage: G. = FreeGroup() - sage: H = Hom(G, G) - sage: H(H.identity()) + sage: G. = FreeGroup() # optional - sage.groups + sage: H = Hom(G, G) # optional - sage.groups + sage: H(H.identity()) # optional - sage.groups Identity endomorphism of Free Group on generators {x, y, z} - sage: H() + sage: H() # optional - sage.groups 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") + sage: H("whatever") # optional - sage.groups 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) - sage: HH(HH.identity(), foo="bar") + sage: HH = Hom(H, H) # optional - sage.groups + sage: HH(HH.identity(), foo="bar") # optional - sage.groups Traceback (most recent call last): ... NotImplementedError: no keywords are implemented for @@ -982,41 +1004,41 @@ class of ``C`` will be inherited by *all* subcategories of this point this is the simplest one to create (gosh):: sage: cat = Groups().Finite().Commutative() - 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() + 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 Category of finite commutative groups - sage: H.category() + sage: H.category() # optional - sage.groups Category of homsets of unital magmas - sage: cls = H._abstract_element_class; cls + sage: cls = H._abstract_element_class; cls # optional - sage.groups - sage: cls.__bases__ == (H.category().element_class, H.homset_category().morphism_class) + sage: cls.__bases__ == (H.category().element_class, H.homset_category().morphism_class) # optional - sage.groups 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) + sage: issubclass(cls, Semigroups().Finite().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Semigroups().morphism_class) + sage: issubclass(cls, Semigroups().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Magmas().Commutative().morphism_class) + sage: issubclass(cls, Magmas().Commutative().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Magmas().morphism_class) + sage: issubclass(cls, Magmas().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Sets().morphism_class) + sage: issubclass(cls, Sets().morphism_class) # optional - sage.groups True Recall that FiniteMonoids() is a full subcategory of ``Monoids()``, but not of ``FiniteSemigroups()``. Thus:: - sage: issubclass(cls, Monoids().Finite().Homsets().element_class) + sage: issubclass(cls, Monoids().Finite().Homsets().element_class) # optional - sage.groups True - sage: issubclass(cls, Semigroups().Finite().Homsets().element_class) + sage: issubclass(cls, Semigroups().Finite().Homsets().element_class) # optional - sage.groups False """ class_name = "%s._abstract_element_class"%self.__class__.__name__ @@ -1117,11 +1139,13 @@ 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']) - sage: H.natural_map() + sage: H = Hom(QQ['t'], GF(3)['t']) # optional - sage.rings.finite_rings + sage: H.natural_map() # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: natural coercion morphism from Univariate Polynomial Ring in t over Rational Field to Univariate Polynomial Ring in t over Finite Field of size 3 not defined + TypeError: natural coercion morphism + from Univariate Polynomial Ring in t over Rational Field + to Univariate Polynomial Ring in t over Finite Field of size 3 not defined """ return morphism.FormalCoercionMorphism(self) # good default in many cases @@ -1162,9 +1186,10 @@ def one(self): EXAMPLES:: - sage: K = GaussianIntegers() - sage: End(K).one() - Identity endomorphism of Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I + sage: K = GaussianIntegers() # optional - sage.rings.number_field + sage: End(K).one() # optional - sage.rings.number_field + Identity endomorphism of Gaussian Integers in Number Field in I + with defining polynomial x^2 + 1 with I = 1*I """ return self.identity() @@ -1205,21 +1230,21 @@ def reversed(self): EXAMPLES:: - sage: H = Hom(ZZ^2, ZZ^3); H + sage: H = Hom(ZZ^2, ZZ^3); H # optional - sage.modules 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) + sage: type(H) # optional - sage.modules - sage: H.reversed() + sage: H.reversed() # optional - sage.modules 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()) + sage: type(H.reversed()) # optional - sage.modules """ return Hom(self.codomain(), self.domain(), diff --git a/src/sage/categories/hopf_algebras.py b/src/sage/categories/hopf_algebras.py index 84858c7c5bf..ecff3fd58cc 100644 --- a/src/sage/categories/hopf_algebras.py +++ b/src/sage/categories/hopf_algebras.py @@ -67,17 +67,18 @@ def antipode(self): EXAMPLES:: - 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() - sage: a, a.antipode() + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - 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,b] = A.algebra_generators() # optional - sage.groups + sage: a, a.antipode() # optional - sage.groups (B[(1,2,3)], B[(1,3,2)]) - sage: b, b.antipode() + sage: b, b.antipode() # optional - sage.groups (B[(1,3)], B[(1,3)]) TESTS:: - sage: all(x.antipode() * x == A.one() for x in A.basis()) + sage: all(x.antipode() * x == A.one() for x in A.basis()) # optional - sage.groups True """ return self.parent().antipode(self) @@ -135,9 +136,9 @@ def antipode(self): EXAMPLES:: - sage: A = SteenrodAlgebra(3) - sage: a = A.an_element() - sage: a, a.antipode() + 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 (2 Q_1 Q_3 P(2,1), Q_1 Q_3 P(2,1)) """ return self.parent().antipode(self) @@ -204,11 +205,11 @@ def antipode_by_coercion(self, x): EXAMPLES:: - sage: N = NonCommutativeSymmetricFunctions(QQ) - sage: R = N.ribbon() - sage: R.antipode_by_coercion.__module__ + sage: N = NonCommutativeSymmetricFunctions(QQ) # optional - sage.combinat + sage: R = N.ribbon() # optional - sage.combinat + sage: R.antipode_by_coercion.__module__ # optional - sage.combinat 'sage.categories.hopf_algebras' - sage: R.antipode_by_coercion(R[1,3,1]) + sage: R.antipode_by_coercion(R[1,3,1]) # optional - sage.combinat -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 79a0b69ce14..ea401896ca0 100644 --- a/src/sage/categories/hopf_algebras_with_basis.py +++ b/src/sage/categories/hopf_algebras_with_basis.py @@ -33,43 +33,44 @@ 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 - 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" - sage: A.category() + sage: A = C.example(); A # optional - 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 Category of finite dimensional hopf algebras with basis over Rational Field - sage: A.one_basis() + sage: A.one_basis() # optional - sage.groups () - sage: A.one() + sage: A.one() # optional - sage.groups B[()] - sage: A.base_ring() + sage: A.base_ring() # optional - sage.groups Rational Field - sage: A.basis().keys() + sage: A.basis().keys() # optional - sage.groups Dihedral group of order 6 as a permutation group - sage: [a,b] = A.algebra_generators() - sage: a, b + sage: [a,b] = A.algebra_generators() # optional - sage.groups + sage: a, b # optional - sage.groups (B[(1,2,3)], B[(1,3)]) - sage: a^3, b^2 + sage: a^3, b^2 # optional - sage.groups (B[()], B[()]) - sage: a*b + sage: a*b # optional - sage.groups B[(1,2)] - sage: A.product # todo: not quite ... + sage: A.product # todo: not quite ... # optional - sage.groups - sage: A.product(b,b) + sage: A.product(b, b) # optional - sage.groups B[()] - sage: A.zero().coproduct() + sage: A.zero().coproduct() # optional - sage.groups 0 - sage: A.zero().coproduct().parent() + sage: A.zero().coproduct().parent() # optional - sage.groups A # A - sage: a.coproduct() + sage: a.coproduct() # optional - sage.groups B[(1,2,3)] # B[(1,2,3)] - sage: TestSuite(A).run(verbose=True) + sage: TestSuite(A).run(verbose=True) # optional - sage.groups running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_antipode() . . . pass @@ -100,32 +101,35 @@ class HopfAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): running ._test_prod() . . . pass running ._test_some_elements() . . . pass running ._test_zero() . . . pass - sage: A.__class__ + sage: A.__class__ # optional - sage.groups - sage: A.element_class + sage: A.element_class # optional - sage.groups Let us look at the code for implementing A:: - sage: A?? # todo: not implemented + sage: A?? # todo: not implemented # optional - sage.groups TESTS:: - sage: TestSuite(A).run() - sage: TestSuite(C).run() + sage: TestSuite(A).run() # optional - sage.groups + sage: TestSuite(C).run() # optional - sage.groups """ def example(self, G=None): """ Returns an example of algebra with basis:: - sage: HopfAlgebrasWithBasis(QQ['x']).example() - 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 + sage: HopfAlgebrasWithBasis(QQ['x']).example() # optional - 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)) - An example of Hopf algebra with basis: the group algebra of the Symmetric group of order 4! as a permutation group over Rational Field + sage: HopfAlgebrasWithBasis(QQ).example(SymmetricGroup(4)) # optional - 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 """ from sage.categories.examples.hopf_algebras_with_basis import MyGroupAlgebra from sage.groups.perm_gps.permgroup_named import DihedralGroup @@ -175,12 +179,12 @@ def antipode_on_basis(self, x): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example() - sage: W = A.basis().keys(); W + sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups + sage: W = A.basis().keys(); W # optional - sage.groups Dihedral group of order 6 as a permutation group - sage: w = W.gen(0); w + sage: w = W.gen(0); w # optional - sage.groups (1,2,3) - sage: A.antipode_on_basis(w) + sage: A.antipode_on_basis(w) # optional - sage.groups B[(1,3,2)] """ @@ -196,18 +200,19 @@ def antipode(self): EXAMPLES:: - 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() - sage: [a,b] = A.algebra_generators() - sage: a, A.antipode(a) + sage: A = HopfAlgebrasWithBasis(ZZ).example(); A # optional - sage.groups + 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 (B[(1,2,3)], B[(1,3,2)]) - sage: b, A.antipode(b) + sage: b, A.antipode(b) # optional - sage.groups (B[(1,3)], B[(1,3)]) TESTS:: - sage: all(A.antipode(x) * x == A.one() for x in A.basis()) + sage: all(A.antipode(x) * x == A.one() for x in A.basis()) # optional - sage.groups True """ if self.antipode_on_basis is not NotImplemented: @@ -239,13 +244,13 @@ def _test_antipode(self, **options): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() - sage: R._test_antipode() + sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() # optional - sage.combinat + sage: R._test_antipode() # optional - sage.combinat :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s._test_antipode() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s._test_antipode() # optional - sage.combinat """ tester = self._tester(**options) diff --git a/src/sage/categories/integral_domains.py b/src/sage/categories/integral_domains.py index 2d5d7730693..ca910a16e60 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() + sage: GF(4, "a") in IntegralDomains() # optional - 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) - sage: L.is_integral_domain() + sage: L. = LazyLaurentSeriesRing(QQ) # optional - sage.combinat + sage: L.is_integral_domain() # optional - sage.combinat True - sage: L.is_integral_domain(proof=True) + sage: L.is_integral_domain(proof=True) # optional - sage.combinat True """ return True @@ -129,7 +129,7 @@ def _test_fraction_field(self, **options): tester = self._tester(**options) try: fraction_field = self.fraction_field() - except AttributeError: + except (AttributeError, ImportError): # some integral domains do not implement fraction_field() yet if self in Fields(): raise diff --git a/src/sage/categories/kac_moody_algebras.py b/src/sage/categories/kac_moody_algebras.py index cd7af55333d..040387a3325 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() + sage: KacMoodyAlgebras(QQ).example() # optional - 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) + sage: KacMoodyAlgebras(QQ).example(4) # optional - 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]) - sage: L.cartan_type() + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules + sage: L.cartan_type() # optional - 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]) - sage: L.weyl_group() + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules + sage: L.weyl_group() # optional - 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 531cfb826b1..8818c0a918a 100644 --- a/src/sage/categories/lambda_bracket_algebras.py +++ b/src/sage/categories/lambda_bracket_algebras.py @@ -45,9 +45,10 @@ def __classcall_private__(cls, R, check=True): EXAMPLES:: - sage: LieConformalAlgebras(QuaternionAlgebra(2)) + sage: LieConformalAlgebras(QuaternionAlgebra(2)) # optional - 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 + ValueError: base must be a commutative ring + got Quaternion Algebra (-1, -1) with base ring Rational Field sage: LieConformalAlgebras(ZZ) Category of Lie conformal algebras over Integer Ring """ @@ -117,8 +118,8 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) - sage: Vir.ideal() + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: Vir.ideal() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: ideals of Lie Conformal algebras are not implemented yet @@ -136,21 +137,21 @@ def bracket(self, rhs): The brackets of the Virasoro Lie conformal algebra:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L.bracket(L) + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules + sage: L.bracket(L) # optional - sage.combinat sage.modules {0: TL, 1: 2*L, 3: 1/2*C} - sage: L.bracket(L.T()) + sage: L.bracket(L.T()) # optional - 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') - sage: V.gens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: V.gens() # optional - sage.combinat sage.modules (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: E = V.0; H = V.1; F = V.2; - sage: H.bracket(H) + sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules + sage: H.bracket(H) # optional - sage.combinat sage.modules {1: 2*B['K']} - sage: E.bracket(F) + sage: E.bracket(F) # optional - sage.combinat sage.modules {0: B[alphacheck[1]], 1: B['K']} """ return self._bracket_(rhs) @@ -169,21 +170,21 @@ def _bracket_(self, rhs): The brackets of the Virasoro Lie conformal Algebra:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L._bracket_(L) + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules + sage: L._bracket_(L) # optional - sage.combinat sage.modules {0: TL, 1: 2*L, 3: 1/2*C} - sage: L._bracket_(L.T()) + sage: L._bracket_(L.T()) # optional - 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') - sage: V.gens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: V.gens() # optional - sage.combinat sage.modules (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: E = V.0; H = V.1; F = V.2; - sage: H._bracket_(H) + sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules + sage: H._bracket_(H) # optional - sage.combinat sage.modules {1: 2*B['K']} - sage: E._bracket_(F) + sage: E._bracket_(F) # optional - sage.combinat sage.modules {0: B[alphacheck[1]], 1: B['K']} """ @@ -194,16 +195,16 @@ def nproduct(self, rhs, n): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L.nproduct(L, 3) + 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 1/2*C - sage: L.nproduct(L.T(), 0) + sage: L.nproduct(L.T(), 0) # optional - sage.combinat sage.modules 2*T^(2)L - 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 + 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 True - sage: E.nproduct(F, 1) + sage: E.nproduct(F, 1) # optional - sage.combinat sage.modules B['K'] """ return self._nproduct_(rhs,n) @@ -219,16 +220,16 @@ def _nproduct_(self, rhs, n): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L._nproduct_(L,3) + 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 1/2*C - sage: L._nproduct_(L.T(),0) + sage: L._nproduct_(L.T(), 0) # optional - sage.combinat sage.modules 2*T^(2)L - 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 + 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 True - sage: E._nproduct_(F,1) + sage: E._nproduct_(F, 1) # optional - sage.combinat sage.modules B['K'] """ if n >= 0: @@ -253,14 +254,14 @@ def T(self, n=1): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) - sage: Vir.inject_variables() + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: Vir.inject_variables() # optional - sage.combinat sage.modules Defining L, C - sage: L.T() + sage: L.T() # optional - sage.combinat sage.modules TL - sage: L.T(3) + sage: L.T(3) # optional - sage.combinat sage.modules 6*T^(3)L - sage: C.T() + sage: C.T() # optional - sage.combinat sage.modules 0 """ diff --git a/src/sage/categories/lambda_bracket_algebras_with_basis.py b/src/sage/categories/lambda_bracket_algebras_with_basis.py index 9b48ba34615..bb0e30908b4 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() + sage: LieConformalAlgebras(QQbar).WithBasis() # optional - sage.rings.number_field Category of Lie conformal algebras with basis over Algebraic Field """ class ElementMethods: @@ -36,14 +36,14 @@ def index(self): EXAMPLES:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: V.inject_variables() + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: V.inject_variables() # optional - sage.combinat sage.modules Defining L, G, C - sage: G.T(3).index() + sage: G.T(3).index() # optional - sage.combinat sage.modules ('G', 3) - sage: v = V.an_element(); v + sage: v = V.an_element(); v # optional - sage.combinat sage.modules L + G + C - sage: v.index() + sage: v.index() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: index can only be computed for monomials, got L + G + C @@ -63,10 +63,14 @@ class FinitelyGeneratedAsLambdaBracketAlgebra(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) - sage: C.WithBasis().FinitelyGenerated() - Category of finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C.WithBasis().FinitelyGenerated() is C.FinitelyGenerated().WithBasis() + sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field + sage: C1 = C.WithBasis().FinitelyGenerated(); C1 # optional - sage.rings.number_field + Category of finitely generated Lie conformal algebras with basis + over Algebraic Field + sage: C2 = C.FinitelyGenerated().WithBasis(); C2 # optional - sage.rings.number_field + Category of finitely generated Lie conformal algebras with basis + over Algebraic Field + sage: C1 is C2 # optional - sage.rings.number_field True """ class Graded(GradedModulesCategory): @@ -76,8 +80,10 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() - Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field + sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field + sage: C.WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + Category of H-graded finitely generated Lie conformal algebras + with basis over Algebraic Field """ class ParentMethods: @@ -88,8 +94,8 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: V = lie_conformal_algebras.Virasoro(QQ) - sage: V.degree_on_basis(('L',2)) + sage: V = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: V.degree_on_basis(('L', 2)) # optional - 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 d29635f078e..3872ca9b51f 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"))) - sage: D.meet( D(6), D(15) ) + sage: D = LatticePoset((divisors(30), attrcall("divides"))) # optional - sage.combinat + sage: D.meet( D(6), D(15) ) # optional - sage.combinat 3 """ @@ -82,7 +82,7 @@ def join(self, x, y): EXAMPLES:: - sage: D = LatticePoset((divisors(60), attrcall("divides"))) - sage: D.join( D(6), D(10) ) + sage: D = LatticePoset((divisors(60), attrcall("divides"))) # optional - sage.combinat + sage: D.join( D(6), D(10) ) # optional - sage.combinat 30 """ diff --git a/src/sage/categories/lie_algebras.py b/src/sage/categories/lie_algebras.py index 269ca3dabbe..04597de0308 100644 --- a/src/sage/categories/lie_algebras.py +++ b/src/sage/categories/lie_algebras.py @@ -45,24 +45,24 @@ class LieAlgebras(Category_over_base_ring): We construct a typical parent in this category, and do some computations with it:: - sage: A = C.example(); A + sage: A = C.example(); A # optional - sage.groups sage.modules 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]) - sage: A.category() + sage: A.category() # optional - sage.groups sage.modules Category of Lie algebras over Rational Field - sage: A.base_ring() + sage: A.base_ring() # optional - sage.groups sage.modules Rational Field - sage: a,b = A.lie_algebra_generators() - sage: a.bracket(b) + sage: a, b = A.lie_algebra_generators() # optional - sage.groups sage.modules + sage: a.bracket(b) # optional - sage.groups sage.modules -[1, 3, 2] + [3, 2, 1] - sage: b.bracket(2*a + b) + sage: b.bracket(2*a + b) # optional - sage.groups sage.modules 2*[1, 3, 2] - 2*[3, 2, 1] - sage: A.bracket(a, b) + sage: A.bracket(a, b) # optional - sage.groups sage.modules -[1, 3, 2] + [3, 2, 1] Please see the source code of `A` (with ``A??``) for how to @@ -70,9 +70,9 @@ class LieAlgebras(Category_over_base_ring): TESTS:: - sage: C = LieAlgebras(QQ) - sage: TestSuite(C).run() - sage: TestSuite(C.example()).run() + sage: C = LieAlgebras(QQ) # optional - sage.combinat sage.modules + sage: TestSuite(C).run() # optional - sage.combinat sage.modules + sage: TestSuite(C.example()).run() # optional - sage.combinat sage.modules .. TODO:: @@ -151,15 +151,15 @@ def example(self, gens=None): EXAMPLES:: - sage: LieAlgebras(QQ).example() + sage: LieAlgebras(QQ).example() # optional - sage.groups sage.modules 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]) Another set of generators can be specified as an optional argument:: - sage: F. = FreeAlgebra(QQ) - sage: LieAlgebras(QQ).example(F.gens()) + sage: F. = FreeAlgebra(QQ) # optional - sage.combinat sage.modules + sage: LieAlgebras(QQ).example(F.gens()) # optional - sage.combinat sage.modules An example of a Lie algebra: the Lie algebra from the associative algebra Free Algebra on 3 generators (x, y, z) over Rational Field generated by (x, y, z) @@ -189,11 +189,14 @@ def extra_super_categories(self): [Category of finite sets] sage: LieAlgebras(ZZ).FiniteDimensional().extra_super_categories() [] - sage: LieAlgebras(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) + sage: C = LieAlgebras(GF(5)).FiniteDimensional() # optional - sage.rings.finite_rings + sage: C.is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings True - sage: LieAlgebras(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) + sage: C = LieAlgebras(ZZ).FiniteDimensional() + sage: C.is_subcategory(Sets().Finite()) False - sage: LieAlgebras(GF(5)).WithBasis().FiniteDimensional().is_subcategory(Sets().Finite()) + sage: C = LieAlgebras(GF(5)).WithBasis().FiniteDimensional() # optional - sage.rings.finite_rings + sage: C.is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings True """ if self.base_ring() in Sets().Finite(): @@ -206,8 +209,8 @@ class Nilpotent(CategoryWithAxiom_over_base_ring): TESTS:: - sage: C = LieAlgebras(QQ).Nilpotent() - sage: TestSuite(C).run() + sage: C = LieAlgebras(QQ).Nilpotent() # optional - sage.combinat sage.modules + sage: TestSuite(C).run() # optional - sage.combinat sage.modules """ class ParentMethods: @abstract_method @@ -217,8 +220,8 @@ def step(self): EXAMPLES:: - sage: h = lie_algebras.Heisenberg(ZZ, oo) - sage: h.step() + sage: h = lie_algebras.Heisenberg(ZZ, oo) # optional - sage.combinat sage.modules + sage: h.step() # optional - sage.combinat sage.modules 2 """ @@ -228,8 +231,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: h = lie_algebras.Heisenberg(ZZ, oo) - sage: h.is_nilpotent() + sage: h = lie_algebras.Heisenberg(ZZ, oo) # optional - sage.combinat sage.modules + sage: h.is_nilpotent() # optional - sage.combinat sage.modules True """ return True @@ -254,30 +257,30 @@ def bracket(self, lhs, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L.bracket(x, x + y) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.bracket(x, x + y) # optional - sage.combinat sage.modules -[1, 3, 2] + [3, 2, 1] - sage: L.bracket(x, 0) + sage: L.bracket(x, 0) # optional - sage.combinat sage.modules 0 - sage: L.bracket(0, x) + sage: L.bracket(0, x) # optional - sage.combinat sage.modules 0 Constructing the product space:: - sage: L = lie_algebras.Heisenberg(QQ, 1) - sage: Z = L.bracket(L, L); Z + sage: L = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: Z = L.bracket(L, L); Z # optional - sage.combinat sage.modules Ideal (z) of Heisenberg algebra of rank 1 over Rational Field - sage: L.bracket(L, Z) + sage: L.bracket(L, Z) # optional - sage.combinat sage.modules Ideal () of Heisenberg algebra of rank 1 over Rational Field Constructing ideals:: - sage: p,q,z = L.basis(); (p,q,z) + sage: p, q, z = L.basis(); p, q, z # optional - sage.combinat sage.modules (p1, q1, z) - sage: L.bracket(3*p, L) + sage: L.bracket(3*p, L) # optional - sage.combinat sage.modules Ideal (3*p1) of Heisenberg algebra of rank 1 over Rational Field - sage: L.bracket(L, q+p) + sage: L.bracket(L, q + p) # optional - sage.combinat sage.modules Ideal (p1 + q1) of Heisenberg algebra of rank 1 over Rational Field """ if lhs in LieAlgebras: @@ -297,15 +300,15 @@ def universal_enveloping_algebra(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.universal_enveloping_algebra() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.universal_enveloping_algebra() # optional - sage.combinat sage.modules Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} :: - sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) - sage: L.universal_enveloping_algebra() + sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) # optional - sage.combinat sage.modules + sage: L.universal_enveloping_algebra() # optional - sage.combinat sage.modules Multivariate Polynomial Ring in x0, x1, x2 over Rational Field .. SEEALSO:: @@ -330,15 +333,15 @@ def _construct_UEA(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L._construct_UEA() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L._construct_UEA() # optional - sage.combinat sage.modules Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} :: - sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) - sage: L.universal_enveloping_algebra() # indirect doctest + sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) # optional - sage.combinat sage.modules + sage: L.universal_enveloping_algebra() # indirect doctest # optional - sage.combinat sage.modules Multivariate Polynomial Ring in x0, x1, x2 over Rational Field """ @@ -394,8 +397,8 @@ def module(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.module() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.module() # optional - sage.combinat sage.modules Vector space of dimension 3 over Rational Field """ @@ -410,10 +413,10 @@ def from_vector(self, v, order=None, coerce=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.combinat sage.modules (1, 0, 0) - sage: parent(u) is L + sage: parent(u) is L # optional - sage.combinat sage.modules True """ @@ -430,11 +433,11 @@ def lift(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: lifted = L.lift(2*a + b - c); lifted + 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: lifted = L.lift(2*a + b - c); lifted # optional - sage.combinat sage.modules 2*b0 + b1 - b2 - sage: lifted.parent() is L.universal_enveloping_algebra() + sage: lifted.parent() is L.universal_enveloping_algebra() # optional - sage.combinat sage.modules True """ M = LiftMorphism(self, self._construct_UEA()) @@ -447,9 +450,9 @@ def subalgebra(self, gens, names=None, index_set=None, category=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.subalgebra([2*a - c, b + c]) + 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.subalgebra([2*a - c, b + c]) # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: the 2-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -458,9 +461,9 @@ def subalgebra(self, gens, names=None, index_set=None, category=None): :: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L.subalgebra([x + y]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.subalgebra([x + y]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: subalgebras not yet implemented: see #17416 @@ -475,9 +478,9 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.ideal([2*a - c, b + c]) + 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.ideal([2*a - c, b + c]) # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: the 2-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -486,9 +489,9 @@ def ideal(self, *gens, **kwds): :: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L.ideal([x + y]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.ideal([x + y]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: ideals not yet implemented: see #16824 @@ -508,8 +511,8 @@ def is_ideal(self, A): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.is_ideal(L) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L.is_ideal(L) # optional - sage.combinat sage.modules True """ if A == self: @@ -525,9 +528,9 @@ def killing_form(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.killing_form(a, b+c) + 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 + c) # optional - sage.combinat sage.modules 0 """ @@ -540,21 +543,21 @@ def is_abelian(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.is_abelian() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules False - sage: R = QQ['x,y'] - sage: L = LieAlgebras(QQ).example(R.gens()) - sage: L.is_abelian() + sage: R = QQ['x,y'] # optional - sage.combinat sage.modules + sage: L = LieAlgebras(QQ).example(R.gens()) # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ,1) # todo: not implemented - #16823 - sage: L.is_abelian() # todo: not implemented - #16823 + sage: L. = LieAlgebra(QQ, 1) # todo: not implemented - #16823 # optional - sage.combinat sage.modules + sage: L.is_abelian() # todo: not implemented - #16823 # optional - sage.combinat sage.modules True - sage: L. = LieAlgebra(QQ,2) # todo: not implemented - #16823 - sage: L.is_abelian() # todo: not implemented - #16823 + sage: L. = LieAlgebra(QQ, 2) # todo: not implemented - #16823 # optional - sage.combinat sage.modules + sage: L.is_abelian() # todo: not implemented - #16823 # optional - sage.combinat sage.modules False """ G = self.lie_algebra_generators() @@ -570,14 +573,14 @@ def is_commutative(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.is_commutative() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L.is_commutative() # optional - sage.combinat sage.modules False :: - sage: L. = LieAlgebra(QQ, 1) # todo: not implemented - #16823 - sage: L.is_commutative() # todo: not implemented - #16823 + sage: L. = LieAlgebra(QQ, 1) # todo: not implemented - #16823 # optional - sage.combinat sage.modules + sage: L.is_commutative() # todo: not implemented - #16823 # optional - sage.combinat sage.modules True """ return self.is_abelian() @@ -589,8 +592,8 @@ def is_solvable(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_solvable() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_solvable() # optional - sage.combinat sage.modules True """ @@ -601,8 +604,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_nilpotent() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_nilpotent() # optional - sage.combinat sage.modules True """ @@ -627,37 +630,40 @@ def bch(self, X, Y, prec=None): The BCH formula for the generators of a free nilpotent Lie algebra of step 4:: - sage: L = LieAlgebra(QQ, 2, step=4) - sage: L.inject_variables() + sage: L = LieAlgebra(QQ, 2, step=4) # optional - sage.combinat sage.modules + sage: L.inject_variables() # optional - sage.combinat sage.modules Defining X_1, X_2, X_12, X_112, X_122, X_1112, X_1122, X_1222 - sage: L.bch(X_1, X_2) + sage: L.bch(X_1, X_2) # optional - sage.combinat sage.modules X_1 + X_2 + 1/2*X_12 + 1/12*X_112 + 1/12*X_122 + 1/24*X_1122 An example of the BCH formula in a quotient:: - sage: Q = L.quotient(X_112 + X_122) - sage: x, y = Q.basis().list()[:2] - sage: Q.bch(x, y) + sage: Q = L.quotient(X_112 + X_122) # optional - sage.combinat sage.modules + sage: x, y = Q.basis().list()[:2] # optional - sage.combinat sage.modules + sage: Q.bch(x, y) # optional - sage.combinat sage.modules X_1 + X_2 + 1/2*X_12 - 1/24*X_1112 The BCH formula for a non-nilpotent Lie algebra requires the precision to be explicitly stated:: - sage: L. = LieAlgebra(QQ) - sage: L.bch(X, Y) + sage: L. = LieAlgebra(QQ) # optional - sage.combinat sage.modules + sage: L.bch(X, Y) # optional - sage.combinat sage.modules Traceback (most recent call last): ... - ValueError: the Lie algebra is not known to be nilpotent, so you must specify the precision - sage: L.bch(X, Y, 4) - X + 1/12*[X, [X, Y]] + 1/24*[X, [[X, Y], Y]] + 1/2*[X, Y] + 1/12*[[X, Y], Y] + Y + ValueError: the Lie algebra is not known to be nilpotent, + so you must specify the precision + sage: L.bch(X, Y, 4) # optional - sage.combinat sage.modules + X + 1/12*[X, [X, Y]] + 1/24*[X, [[X, Y], Y]] + + 1/2*[X, Y] + 1/12*[[X, Y], Y] + Y The BCH formula requires a coercion from the rationals:: - sage: L. = LieAlgebra(ZZ, 2, step=2) - sage: L.bch(X, Y) + sage: L. = LieAlgebra(ZZ, 2, step=2) # optional - sage.combinat sage.modules + sage: L.bch(X, Y) # optional - sage.combinat sage.modules Traceback (most recent call last): ... - TypeError: the BCH formula is not well defined since Integer Ring has no coercion from Rational Field + TypeError: the BCH formula is not well defined + since Integer Ring has no coercion from Rational Field """ if self not in LieAlgebras.Nilpotent and prec is None: raise ValueError("the Lie algebra is not known to be nilpotent," @@ -682,8 +688,8 @@ def lie_group(self, name='G', **kwds): EXAMPLES:: - sage: L = lie_algebras.Heisenberg(QQ, 1) - sage: G = L.lie_group('G'); G # optional - sage.symbolic + 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 Lie group G of Heisenberg algebra of rank 1 over Rational Field """ @@ -701,15 +707,15 @@ def _test_jacobi_identity(self, **options): By default, this method runs the tests only on the elements returned by ``self.some_elements()``:: - sage: L = LieAlgebras(QQ).example() - sage: L._test_jacobi_identity() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L._test_jacobi_identity() # optional - sage.combinat sage.modules However, the elements tested can be customized with the ``elements`` keyword argument:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L._test_jacobi_identity(elements=[x+y, x, 2*y, x.bracket(y)]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L._test_jacobi_identity(elements=[x + y, x, 2*y, x.bracket(y)]) # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. """ @@ -740,15 +746,15 @@ def _test_antisymmetry(self, **options): By default, this method runs the tests only on the elements returned by ``self.some_elements()``:: - sage: L = LieAlgebras(QQ).example() - sage: L._test_antisymmetry() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L._test_antisymmetry() # optional - sage.combinat sage.modules However, the elements tested can be customized with the ``elements`` keyword argument:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L._test_antisymmetry(elements=[x+y, x, 2*y, x.bracket(y)]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L._test_antisymmetry(elements=[x + y, x, 2*y, x.bracket(y)]) # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. """ @@ -769,27 +775,27 @@ def _test_distributivity(self, **options): TESTS:: - sage: L = LieAlgebras(QQ).example() - sage: L._test_distributivity() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L._test_distributivity() # optional - sage.combinat sage.modules EXAMPLES: By default, this method runs the tests only on the elements returned by ``self.some_elements()``:: - sage: L = LieAlgebra(QQ, 3, 'x,y,z', representation="polynomial") - sage: L.some_elements() + sage: L = LieAlgebra(QQ, 3, 'x,y,z', representation="polynomial") # optional - sage.combinat sage.modules + sage: L.some_elements() # optional - sage.combinat sage.modules [x + y + z] - sage: L._test_distributivity() + sage: L._test_distributivity() # optional - sage.combinat sage.modules However, the elements tested can be customized with the ``elements`` keyword argument:: - sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # todo: not implemented - #16821 - sage: h1 = L.gen(0) # todo: not implemented - #16821 - sage: h2 = L.gen(1) # todo: not implemented - #16821 - sage: e2 = L.gen(3) # todo: not implemented - #16821 - sage: L._test_distributivity(elements=[h1, h2, e2]) # todo: not implemented - #16821 + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: h1 = L.gen(0) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: h2 = L.gen(1) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: e2 = L.gen(3) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: L._test_distributivity(elements=[h1, h2, e2]) # todo: not implemented - #16821 # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. """ @@ -812,11 +818,11 @@ def bracket(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x.bracket(y) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: x.bracket(y) # optional - sage.combinat sage.modules -[1, 3, 2] + [3, 2, 1] - sage: x.bracket(0) + sage: x.bracket(0) # optional - sage.combinat sage.modules 0 """ return self._bracket_(rhs) @@ -831,13 +837,13 @@ def _bracket_(self, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x._bracket_(y) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: x._bracket_(y) # optional - sage.combinat sage.modules -[1, 3, 2] + [3, 2, 1] - sage: y._bracket_(x) + sage: y._bracket_(x) # optional - sage.combinat sage.modules [1, 3, 2] - [3, 2, 1] - sage: x._bracket_(x) + sage: x._bracket_(x) # optional - sage.combinat sage.modules 0 """ @@ -853,10 +859,10 @@ def to_vector(self, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: u = L((1, 0, 0)).to_vector(); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: u = L((1, 0, 0)).to_vector(); u # optional - sage.combinat sage.modules (1, 0, 0) - sage: parent(u) + sage: parent(u) # optional - sage.combinat sage.modules Vector space of dimension 3 over Rational Field """ @@ -868,16 +874,16 @@ def lift(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: elt = 3*a + b - c - sage: elt.lift() + 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: elt = 3*a + b - c # optional - sage.combinat sage.modules + sage: elt.lift() # optional - sage.combinat sage.modules 3*b0 + b1 - b2 :: - sage: L. = LieAlgebra(QQ, abelian=True) - sage: x.lift() + sage: L. = LieAlgebra(QQ, abelian=True) # optional - sage.combinat sage.modules + sage: x.lift() # optional - sage.combinat sage.modules x """ @@ -887,9 +893,9 @@ def killing_form(self, x): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: a.killing_form(b) + 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: a.killing_form(b) # optional - sage.combinat sage.modules 0 """ return self.parent().killing_form(self, x) @@ -906,24 +912,26 @@ def exp(self, lie_group=None): EXAMPLES:: - sage: L. = LieAlgebra(QQ, 2, step=2) - sage: g = (X + Y + Z).exp(); g # optional - sage.symbolic + sage: L. = LieAlgebra(QQ, 2, step=2) # optional - sage.combinat sage.modules + sage: g = (X + Y + Z).exp(); g # optional - sage.combinat sage.modules sage.symbolic exp(X + Y + Z) - sage: h = X.exp(); h # optional - sage.symbolic + sage: h = X.exp(); h # optional - sage.combinat sage.modules sage.symbolic exp(X) - sage: g.parent() # optional - sage.symbolic - Lie group G of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) over Rational Field - sage: g.parent() is h.parent() # optional - sage.symbolic + sage: g.parent() # optional - sage.combinat sage.modules sage.symbolic + Lie group G of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) + over Rational Field + sage: g.parent() is h.parent() # optional - sage.combinat sage.modules sage.symbolic True The Lie group can be specified explicitly:: - sage: H = L.lie_group('H') # optional - sage.symbolic - sage: k = Z.exp(lie_group=H); k # optional - sage.symbolic + sage: H = L.lie_group('H') # optional - sage.combinat sage.modules sage.symbolic + sage: k = Z.exp(lie_group=H); k # optional - sage.combinat sage.modules sage.symbolic exp(Z) - sage: k.parent() # optional - sage.symbolic - Lie group H of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) over Rational Field - sage: g.parent() == k.parent() # optional - sage.symbolic + sage: k.parent() # optional - sage.combinat sage.modules sage.symbolic + Lie group H of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) + over Rational Field + sage: g.parent() == k.parent() # optional - sage.combinat sage.modules sage.symbolic False """ if lie_group is None: @@ -941,13 +949,13 @@ def __init__(self, domain, codomain): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: f = L.lift + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: f = L.lift # optional - sage.combinat sage.modules We skip the category test since this is currently not an element of a homspace:: - sage: TestSuite(f).run(skip="_test_category") + sage: TestSuite(f).run(skip="_test_category") # optional - sage.combinat sage.modules """ Morphism.__init__(self, Hom(domain, codomain)) @@ -957,9 +965,9 @@ def _call_(self, x): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.lift(3*a + b - c) + 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.lift(3*a + b - c) # optional - sage.combinat sage.modules 3*b0 + b1 - b2 """ return x.lift() diff --git a/src/sage/categories/lie_algebras_with_basis.py b/src/sage/categories/lie_algebras_with_basis.py index 71916e3d6ad..4f6cf394651 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() + sage: LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat 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()) + sage: LieAlgebras(QQ).WithBasis().example(Compositions()) # optional - sage.combinat 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() - sage: L._basis_key(Partition([3,1])) + sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat + sage: L._basis_key(Partition([3,1])) # optional - sage.combinat [3, 1] """ return x @@ -79,8 +79,8 @@ def bracket_on_basis(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() - sage: L.bracket_on_basis(Partition([3,1]), Partition([2,2,1,1])) + 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 0 """ @@ -95,8 +95,8 @@ def module(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() - sage: L.module() + sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat + sage: L.module() # optional - sage.combinat 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() - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.combinat (1, 0, 0) - sage: parent(u) is L + sage: parent(u) is L # optional - sage.combinat True """ B = self.basis() @@ -135,14 +135,14 @@ def dimension(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.dimension() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat + sage: L.dimension() # optional - sage.combinat 3 :: - sage: L = LieAlgebra(QQ, 'x,y', {('x','y'): {'x':1}}) - sage: L.dimension() + sage: L = LieAlgebra(QQ, 'x,y', {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.dimension() # optional - 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) - sage: PBW = L.pbw_basis() + sage: L = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules + sage: PBW = L.pbw_basis() # optional - sage.combinat sage.modules """ from sage.algebras.lie_algebras.poincare_birkhoff_witt \ import PoincareBirkhoffWittBasis @@ -173,11 +173,11 @@ def _bracket_(self, y): EXAMPLES:: - 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) + 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 0 """ P = self.parent() @@ -206,8 +206,8 @@ def to_vector(self, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.an_element().to_vector() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L.an_element().to_vector() # optional - sage.modules (0, 0, 0) .. TODO:: @@ -224,15 +224,15 @@ def lift(self): EXAMPLES:: - sage: S = SymmetricGroup(3).algebra(QQ) - sage: L = LieAlgebra(associative=S) - sage: x = L.gen(3) - sage: y = L.gen(1) - sage: x.lift() + 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 b3 - sage: y.lift() + sage: y.lift() # optional - sage.groups b1 - sage: x * y + sage: x * y # optional - sage.groups 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 54e3956c283..4e59d4758b0 100644 --- a/src/sage/categories/lie_conformal_algebras.py +++ b/src/sage/categories/lie_conformal_algebras.py @@ -152,15 +152,16 @@ class LieConformalAlgebras(Category_over_base_ring): Some subcategories:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().WithBasis() - Category of finitely generated Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().WithBasis() # optional - 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: LieConformalAlgebras(AA).Graded().Super() + sage: CGS = LieConformalAlgebras(AA).Graded().Super(); CGS # optional - sage.rings.number_field Category of H-graded super Lie conformal algebras over Algebraic Real Field - sage: LieConformalAlgebras(AA).Graded().Super() is LieConformalAlgebras(AA).Super().Graded() + sage: CGS is LieConformalAlgebras(AA).Super().Graded() # optional - sage.rings.number_field True That is, we only consider gradings on super Lie conformal algebras @@ -168,9 +169,10 @@ class LieConformalAlgebras(Category_over_base_ring): The base ring needs to be a commutative ring:: - sage: LieConformalAlgebras(QuaternionAlgebra(2)) + sage: LieConformalAlgebras(QuaternionAlgebra(2)) # optional - 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 + ValueError: base must be a commutative ring + got Quaternion Algebra (-1, -1) with base ring Rational Field """ @cached_method def super_categories(self): @@ -219,7 +221,7 @@ def example(self): EXAMPLES:: - sage: LieConformalAlgebras(QQ).example() + sage: LieConformalAlgebras(QQ).example() # optional - sage.combinat sage.modules The Virasoro Lie conformal algebra over Rational Field """ from sage.algebras.lie_conformal_algebras.virasoro_lie_conformal_algebra\ @@ -252,27 +254,27 @@ 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') - sage: V._test_jacobi() # long time (6 seconds) + 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 It works for super Lie conformal algebras too:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: V._test_jacobi() + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: V._test_jacobi() # optional - 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')) - sage: V.inject_variables() + 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 Defining e, h, f, K - sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) + sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) # optional - 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)) - sage: V._test_jacobi() + 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 Traceback (most recent call last): ... AssertionError: {(0, 0): -3*a} != {} @@ -323,10 +325,10 @@ def is_even_odd(self): EXAMPLES:: - sage: R = lie_conformal_algebras.NeveuSchwarz(QQ); - sage: R.inject_variables() + sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: R.inject_variables() # optional - sage.combinat sage.modules Defining L, G, C - sage: G.is_even_odd() + sage: G.is_even_odd() # optional - 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 50f67d2a970..6f31b6b4cca 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() + sage: LieConformalAlgebras(QQbar).WithBasis() # optional - sage.rings.number_field Category of Lie conformal algebras with basis over Algebraic Field """ class Super(SuperModulesCategory): @@ -36,8 +36,9 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).WithBasis().Super() - Category of super Lie conformal algebras with basis over Algebraic Real Field + sage: LieConformalAlgebras(AA).WithBasis().Super() # optional - sage.rings.number_field + Category of super Lie conformal algebras with basis + over Algebraic Real Field """ class ParentMethods: @@ -52,9 +53,9 @@ def _even_odd_on_basis(self, m): EXAMPLES:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: B = V._indices - sage: V._even_odd_on_basis(B(('G',1))) + 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 1 """ return self._parity[self.monomial((m[0],0))] @@ -65,8 +66,9 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().Super().Graded() - Category of H-graded super Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).WithBasis().Super().Graded() # optional - sage.rings.number_field + Category of H-graded super Lie conformal algebras with basis + over Algebraic Field """ class Graded(GradedLieConformalAlgebrasCategory): @@ -75,7 +77,7 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().Graded() + sage: LieConformalAlgebras(QQbar).WithBasis().Graded() # optional - sage.rings.number_field Category of H-graded Lie conformal algebras with basis over Algebraic Field """ @@ -86,10 +88,11 @@ class FinitelyGeneratedAsLambdaBracketAlgebra(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) - sage: C.WithBasis().FinitelyGenerated() - Category of finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C.WithBasis().FinitelyGenerated() is C.FinitelyGenerated().WithBasis() + sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field + sage: CWF = C.WithBasis().FinitelyGenerated(); CWF # optional - 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 True """ class Super(SuperModulesCategory): @@ -99,8 +102,9 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).WithBasis().FinitelyGenerated().Super() - Category of super finitely generated Lie conformal algebras with basis over Algebraic Real Field + sage: LieConformalAlgebras(AA).WithBasis().FinitelyGenerated().Super() # optional - sage.rings.number_field + Category of super finitely generated Lie conformal algebras with basis + over Algebraic Real Field """ class Graded(GradedModulesCategory): """ @@ -109,10 +113,11 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() - sage: C.Graded().Super() - Category of H-graded super finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C.Graded().Super() is C.Super().Graded() + sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # optional - sage.rings.number_field + sage: C.Graded().Super() # optional - 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 True """ def _repr_object_names(self): @@ -121,8 +126,8 @@ def _repr_object_names(self): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() - sage: C.Super().Graded() + sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # optional - sage.rings.number_field + sage: C.Super().Graded() # optional - 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()) @@ -134,6 +139,7 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() - Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - 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 415d8c308f7..b7dbd37a3c6 100644 --- a/src/sage/categories/loop_crystals.py +++ b/src/sage/categories/loop_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs sage.combinat r""" Loop Crystals """ @@ -390,11 +391,17 @@ def R_matrix(self, K): sage: K2 = crystals.KirillovReshetikhin(['A',2,1],2,1) sage: T1 = crystals.TensorProduct(K1,K2) sage: T2 = crystals.TensorProduct(K2,K1) - sage: T1.digraph().is_isomorphic(T2.digraph(), edge_labels=True, certificate=True) #todo: not implemented (see #10904 and #10549) - (True, {[[[1]], [[2], [3]]]: [[[1], [3]], [[2]]], [[[3]], [[2], [3]]]: [[[2], [3]], [[3]]], - [[[3]], [[1], [3]]]: [[[1], [3]], [[3]]], [[[1]], [[1], [3]]]: [[[1], [3]], [[1]]], [[[1]], - [[1], [2]]]: [[[1], [2]], [[1]]], [[[2]], [[1], [2]]]: [[[1], [2]], [[2]]], [[[3]], - [[1], [2]]]: [[[2], [3]], [[1]]], [[[2]], [[1], [3]]]: [[[1], [2]], [[3]]], [[[2]], [[2], [3]]]: [[[2], [3]], [[2]]]}) + sage: T1.digraph().is_isomorphic(T2.digraph(), edge_labels=True, # todo: not implemented (see #10904 and #10549) + ....: certificate=True) + (True, {[[[1]], [[2], [3]]]: [[[1], [3]], [[2]]], + [[[3]], [[2], [3]]]: [[[2], [3]], [[3]]], + [[[3]], [[1], [3]]]: [[[1], [3]], [[3]]], + [[[1]], [[1], [3]]]: [[[1], [3]], [[1]]], [[[1]], + [[1], [2]]]: [[[1], [2]], [[1]]], + [[[2]], [[1], [2]]]: [[[1], [2]], [[2]]], [[[3]], + [[1], [2]]]: [[[2], [3]], [[1]]], + [[[2]], [[1], [3]]]: [[[1], [2]], [[3]]], + [[[2]], [[2], [3]]]: [[[2], [3]], [[2]]]}) """ from sage.combinat.crystals.tensor_product import TensorProductOfCrystals T1 = TensorProductOfCrystals(self, K) @@ -514,7 +521,7 @@ def is_perfect(self, ell=None): sage: K.is_perfect() True - sage: K = crystals.KirillovReshetikhin(['E',6,1], 1,3) + sage: K = crystals.KirillovReshetikhin(['E',6,1], 1, 3) sage: K.is_perfect() True @@ -523,7 +530,7 @@ def is_perfect(self, ell=None): Check that this works correctly for `B^{n,s}` of type `A_{2n}^{(2)\dagger}` (:trac:`24364`):: - sage: K = crystals.KirillovReshetikhin(CartanType(['A',6,2]).dual(), 3,1) + sage: K = crystals.KirillovReshetikhin(CartanType(['A',6,2]).dual(), 3, 1) sage: K.is_perfect() True sage: K.is_perfect(1) @@ -835,7 +842,8 @@ def one_dimensional_configuration_sum(self, q=None, group_components=True): sage: R = RootSystem(['A',2,1]) sage: La = R.weight_space().basis() sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]) - sage: LS.one_dimensional_configuration_sum() == T.one_dimensional_configuration_sum() # long time + sage: (LS.one_dimensional_configuration_sum() # long time + ....: == T.one_dimensional_configuration_sum()) True TESTS:: diff --git a/src/sage/categories/magmas.py b/src/sage/categories/magmas.py index 33dc2bb973a..e80088548a9 100644 --- a/src/sage/categories/magmas.py +++ b/src/sage/categories/magmas.py @@ -296,11 +296,13 @@ def Distributive(self): sage: Magmas().Distributive() Traceback (most recent call last): ... - ValueError: The distributive axiom only makes sense on a magma which is simultaneously an additive magma + ValueError: The distributive axiom only makes sense on a magma + which is simultaneously an additive magma sage: Semigroups().Distributive() Traceback (most recent call last): ... - ValueError: The distributive axiom only makes sense on a magma which is simultaneously an additive magma + ValueError: The distributive axiom only makes sense on a magma + which is simultaneously an additive magma TESTS:: @@ -331,7 +333,8 @@ def JTrivial(self): sage: Magmas().JTrivial() Category of j trivial magmas - sage: (Semigroups().RTrivial() & Semigroups().LTrivial()) is Semigroups().JTrivial() + sage: C = Semigroups().RTrivial() & Semigroups().LTrivial() + sage: C is Semigroups().JTrivial() True """ return self._with_axiom('JTrivial') @@ -349,19 +352,22 @@ def extra_super_categories(self): """ EXAMPLES:: - sage: Magmas().Commutative().Algebras(QQ).extra_super_categories() + sage: MCA = Magmas().Commutative().Algebras(QQ) + sage: MCA.extra_super_categories() [Category of commutative magmas] This implements the fact that the algebra of a commutative magma is commutative:: - sage: Magmas().Commutative().Algebras(QQ).super_categories() - [Category of magma algebras over Rational Field, Category of commutative magmas] + sage: MCA.super_categories() + [Category of magma algebras over Rational Field, + Category of commutative magmas] In particular, commutative monoid algebras are commutative algebras:: - sage: Monoids().Commutative().Algebras(QQ).is_subcategory(Algebras(QQ).Commutative()) + sage: MoCA = Monoids().Commutative().Algebras(QQ) + sage: MoCA.is_subcategory(Algebras(QQ).Commutative()) True """ from sage.categories.magmatic_algebras import MagmaticAlgebras @@ -377,11 +383,11 @@ def is_field(self, proof=True): EXAMPLES:: - sage: SymmetricGroup(1).algebra(QQ).is_field() + sage: SymmetricGroup(1).algebra(QQ).is_field() # optional - sage.groups True - sage: SymmetricGroup(1).algebra(ZZ).is_field() + sage: SymmetricGroup(1).algebra(ZZ).is_field() # optional - sage.groups False - sage: SymmetricGroup(2).algebra(QQ).is_field() + sage: SymmetricGroup(2).algebra(QQ).is_field() # optional - sage.groups False """ if not self.base_ring().is_field(proof): @@ -397,7 +403,7 @@ def is_commutative(self): EXAMPLES:: - sage: Parent(QQ,category=CommutativeRings()).is_commutative() + sage: Parent(QQ, category=CommutativeRings()).is_commutative() True """ return True @@ -408,20 +414,22 @@ def extra_super_categories(self): """ EXAMPLES:: - sage: Magmas().Commutative().Algebras(QQ).extra_super_categories() + sage: MCA = Magmas().Commutative().Algebras(QQ) + sage: MCA.extra_super_categories() [Category of commutative magmas] This implements the fact that the algebra of a commutative magma is commutative:: - sage: Magmas().Commutative().Algebras(QQ).super_categories() + sage: MCA.super_categories() [Category of magma algebras over Rational Field, Category of commutative magmas] In particular, commutative monoid algebras are commutative algebras:: - sage: Monoids().Commutative().Algebras(QQ).is_subcategory(Algebras(QQ).Commutative()) + sage: MoCA = Monoids().Commutative().Algebras(QQ) + sage: MoCA.is_subcategory(Algebras(QQ).Commutative()) True """ return [Magmas().Commutative()] @@ -480,7 +488,8 @@ def one(self): EXAMPLES:: sage: M = Monoids().example(); M - An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') + An example of a monoid: + the free monoid generated by ('a', 'b', 'c', 'd') sage: M.one() '' """ @@ -531,8 +540,8 @@ def is_empty(self): EXAMPLES:: - sage: S = SymmetricGroup(2) - sage: S.is_empty() + sage: S = SymmetricGroup(2) # optional - sage.groups + sage: S.is_empty() # optional - sage.groups False sage: M = Monoids().example() @@ -541,7 +550,7 @@ def is_empty(self): TESTS:: - sage: S.is_empty.__module__ + sage: S.is_empty.__module__ # optional - sage.groups 'sage.categories.magmas' sage: M.is_empty.__module__ 'sage.categories.magmas' @@ -656,21 +665,21 @@ def __invert__(self): EXAMPLES:: - sage: C = cartesian_product([QQ, ZZ, RR, GF(5)]) - sage: c = C([2,-1,2,2]); c + 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 (2, -1, 2.00000000000000, 2) - sage: ~c + sage: ~c # optional - sage.rings.finite_rings (1/2, -1, 0.500000000000000, 3) This fails as soon as one of the entries is not invertible:: - sage: ~C([0,2,2,2]) + sage: ~C([0,2,2,2]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: rational division by zero - sage: ~C([2,2,2,2]) + sage: ~C([2,2,2,2]) # optional - sage.rings.finite_rings (1/2, 1/2, 0.500000000000000, 3) """ # variant without coercion: @@ -684,20 +693,22 @@ def extra_super_categories(self): """ EXAMPLES:: - sage: Magmas().Commutative().Algebras(QQ).extra_super_categories() + sage: MCA = Magmas().Commutative().Algebras(QQ) + sage: MCA.extra_super_categories() [Category of commutative magmas] This implements the fact that the algebra of a commutative magma is commutative:: - sage: Magmas().Commutative().Algebras(QQ).super_categories() + sage: MCA.super_categories() [Category of magma algebras over Rational Field, Category of commutative magmas] In particular, commutative monoid algebras are commutative algebras:: - sage: Monoids().Commutative().Algebras(QQ).is_subcategory(Algebras(QQ).Commutative()) + sage: MoCA = Monoids().Commutative().Algebras(QQ) + sage: MoCA.is_subcategory(Algebras(QQ).Commutative()) True """ return [Magmas().Unital()] @@ -713,11 +724,11 @@ def one(self): EXAMPLES:: - 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() + 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 True - sage: PvW0.one() + sage: PvW0.one() # optional - sage.combinat sage.groups 1 """ return self(self.realization_of().a_realization().one()) @@ -758,7 +769,8 @@ def product(self, x, y): Currently, ``S.product`` is just a bound method:: sage: bin - + When Sage will support multivariate morphisms, it will be possible, and in fact recommended, to enrich ``S.product`` @@ -872,8 +884,8 @@ def multiplication_table(self, names='letters', elements=None): The default is to represent elements as lowercase ASCII letters. :: - sage: G = CyclicPermutationGroup(5) - sage: G.multiplication_table() + sage: G = CyclicPermutationGroup(5) # optional - sage.groups + sage: G.multiplication_table() # optional - sage.groups * a b c d e +---------- a| a b c d e @@ -890,10 +902,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') - sage: T.column_keys() + sage: T = L.multiplication_table(names='digits') # optional - sage.matrix + sage: T.column_keys() # optional - sage.matrix ('a', 'ab', 'b', 'ba') - sage: T + sage: T # optional - sage.matrix * 0 1 2 3 +-------- 0| 0 1 1 1 @@ -906,7 +918,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) + sage: L.multiplication_table(elements=elts) # optional - sage.matrix * 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 @@ -935,7 +947,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) + sage: L.multiplication_table(names='elements', elements=elts) # optional - sage.matrix * 'a' 'c' 'ac' 'ca' +-------------------- 'a'| 'a' 'ac' 'ac' 'ac' @@ -948,16 +960,16 @@ def multiplication_table(self, names='letters', elements=None): :class:`~sage.matrix.operation_table.OperationTable` for more comprehensive documentation. :: - sage: G = AlternatingGroup(3) - sage: T = G.multiplication_table() - sage: T.column_keys() + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = G.multiplication_table() # optional - sage.groups sage.matrix + sage: T.column_keys() # optional - sage.groups sage.matrix ((), (1,2,3), (1,3,2)) - sage: T.translation() + sage: T.translation() # optional - sage.groups sage.matrix {'a': (), 'b': (1,2,3), 'c': (1,3,2)} - sage: T.change_names(['x', 'y', 'z']) - sage: T.translation() + sage: T.change_names(['x', 'y', 'z']) # optional - sage.groups sage.matrix + sage: T.translation() # optional - sage.groups sage.matrix {'x': (), 'y': (1,2,3), 'z': (1,3,2)} - sage: T + sage: T # optional - sage.groups sage.matrix * x y z +------ x| x y z @@ -999,7 +1011,8 @@ def is_idempotent(self): EXAMPLES:: sage: S = Semigroups().example("free"); S - An example of a semigroup: the free semigroup generated by ('a', 'b', 'c', 'd') + An example of a semigroup: + the free semigroup generated by ('a', 'b', 'c', 'd') sage: a = S('a') sage: a^2 'aa' @@ -1071,12 +1084,12 @@ def product(self, left, right): sage: x * x (1/4, 1, 1) - 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) + 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 B[(0, [1, 2, 3])] + B[(1, [3, 1, 2])] - sage: x*y + sage: x*y # optional - sage.groups B[(0, [1, 2, 3])] + B[(1, [3, 1, 2])] """ prods = ((a * b) for a, b in zip(left.cartesian_factors(), @@ -1125,9 +1138,9 @@ def product(self, x, y): Here is a more elaborate example involving a sub algebra:: - sage: Z = SymmetricGroup(5).algebra(QQ).center() - sage: B = Z.basis() - sage: B[3] * B[2] + 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 4*B[2] + 6*B[3] + 5*B[6] """ assert x in self @@ -1149,15 +1162,18 @@ def product_by_coercion(self, left, right): EXAMPLES:: - sage: Out = Sets().WithRealizations().example().Out(); Out - The subset algebra of {1, 2, 3} over Rational Field in the Out basis - sage: Out.product - - sage: Out.product.__module__ + sage: Out = Sets().WithRealizations().example().Out(); Out # optional - sage.combinat sage.modules + 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.__module__ # optional - sage.combinat sage.modules 'sage.categories.magmas' - sage: x = Out.an_element() - sage: y = Out.an_element() - sage: Out.product(x, y) + 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 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 ef82ba4319b..171f564534e 100644 --- a/src/sage/categories/magmatic_algebras.py +++ b/src/sage/categories/magmatic_algebras.py @@ -40,7 +40,8 @@ class MagmaticAlgebras(Category_over_base_ring): sage: C = MagmaticAlgebras(ZZ); C Category of magmatic algebras over Integer Ring sage: C.super_categories() - [Category of additive commutative additive associative additive unital distributive magmas and additive magmas, + [Category of additive commutative additive associative additive + unital distributive magmas and additive magmas, Category of modules over Integer Ring] TESTS:: @@ -54,11 +55,14 @@ def super_categories(self): EXAMPLES:: sage: from sage.categories.magmatic_algebras import MagmaticAlgebras - sage: MagmaticAlgebras(ZZ).super_categories() - [Category of additive commutative additive associative additive unital distributive magmas and additive magmas, Category of modules over Integer Ring] + sage: MA = MagmaticAlgebras(ZZ) + sage: MA.super_categories() + [Category of additive commutative additive associative additive + unital distributive magmas and additive magmas, + Category of modules over Integer Ring] sage: from sage.categories.additive_semigroups import AdditiveSemigroups - sage: MagmaticAlgebras(ZZ).is_subcategory((AdditiveSemigroups() & Magmas()).Distributive()) + sage: MA.is_subcategory((AdditiveSemigroups() & Magmas()).Distributive()) True """ @@ -106,9 +110,10 @@ def algebra_generators(self): EXAMPLES:: - sage: F = AlgebrasWithBasis(QQ).example(); F - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: F.algebra_generators() + sage: F = AlgebrasWithBasis(QQ).example(); F # optional - 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 Family (B[word: a], B[word: b], B[word: c]) """ @@ -131,16 +136,18 @@ def algebra_generators(self): EXAMPLES:: - sage: D4 = DescentAlgebra(QQ, 4).B() - sage: D4.algebra_generators() + sage: D4 = DescentAlgebra(QQ, 4).B() # optional - sage.combinat sage.modules + sage: D4.algebra_generators() # optional - sage.combinat sage.modules Lazy family (...)_{i in Compositions of 4} sage: R. = ZZ[] - sage: P = PartitionAlgebra(1, x, R) - sage: P.algebra_generators() - Lazy family (Term map from Partition diagrams of order 1 to - Partition Algebra of rank 1 with parameter x over Univariate Polynomial Ring in x - over Integer Ring(i))_{i in Partition diagrams of order 1} + sage: P = PartitionAlgebra(1, x, R) # optional - sage.combinat sage.modules + sage: P.algebra_generators() # optional - sage.combinat sage.modules + Lazy family (Term map + from Partition diagrams of order 1 + to Partition Algebra of rank 1 with parameter x + over Univariate Polynomial Ring in x + over Integer Ring(i))_{i in Partition diagrams of order 1} """ return self.basis() @@ -162,9 +169,9 @@ def product_on_basis(self, i, j): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: Word = A.basis().keys() - sage: A.product_on_basis(Word("abc"),Word("cba")) + 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 B[word: abccba] """ @@ -183,9 +190,9 @@ def product(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: a, b, c = A.algebra_generators() - sage: A.product(a + 2*b, 3*c) + 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 3*B[word: ac] + 6*B[word: bc] """ if self.product_on_basis is not NotImplemented: @@ -205,10 +212,11 @@ def _product_from_product_on_basis_multiply( self, left, right ): EXAMPLES:: - 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,b,c) = A.algebra_generators() - sage: A._product_from_product_on_basis_multiply(a*b + 2*c, a - b) + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - 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 B[word: aba] - B[word: abb] + 2*B[word: ca] - 2*B[word: cb] """ @@ -239,17 +247,17 @@ 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]]) - 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() + 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 + ....: [p_mult, q_mult, matrix(QQ, 3, 3)], 'p,q,z') + sage: A.inject_variables() # optional - sage.combinat sage.modules Defining p, q, z - sage: p*q + sage: p * q # optional - sage.combinat sage.modules z - sage: q*p + sage: q * p # optional - sage.combinat sage.modules -z - sage: A.derivations_basis() + sage: A.derivations_basis() # optional - sage.combinat sage.modules ( [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] @@ -259,15 +267,16 @@ def derivations_basis(self): We construct another example using the exterior algebra and verify we obtain a derivation:: - sage: A = algebras.Exterior(QQ, 1) - sage: A.derivations_basis() + sage: A = algebras.Exterior(QQ, 1) # optional - sage.combinat sage.modules + sage: A.derivations_basis() # optional - sage.combinat sage.modules ( [0 0] [0 1] ) - sage: D = A.module_morphism(matrix=A.derivations_basis()[0], codomain=A) - sage: one, e = A.basis() - sage: all(D(a*b) == D(a) * b + a * D(b) + sage: D = A.module_morphism(matrix=A.derivations_basis()[0], # optional - sage.combinat sage.modules + ....: 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 ....: for a in A.basis() for b in A.basis()) True diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index 5a7445913bb..39d37acc2ae 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)) + sage: Map(QQ['x'], SymmetricGroup(6)) # optional - sage.groups Generic map: From: Univariate Polynomial Ring in x over Rational Field To: Symmetric group of order 6! as a permutation group @@ -196,34 +196,44 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_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: 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 + Set of field embeddings + from Number Field in a with defining polynomial x^2 + 5 + with a = 2.236067977499790?*I + to Complex Double Field We now demonstrate that the reference to the coercion map `\phi` does not prevent `Q` from being garbage collected:: sage: import gc - sage: del Q + sage: del Q # optional - sage.rings.number_field sage: _ = gc.collect() - sage: phi.parent() + sage: phi.parent() # optional - sage.rings.number_field Traceback (most recent call last): ... - ValueError: This map is in an invalid state, the domain has been garbage collected + ValueError: This map is in an invalid state, + the domain has been garbage collected You can still obtain copies of the maps used by the coercion system with strong references:: - 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: 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 + 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 + sage: del Q # optional - sage.rings.number_field sage: _ = gc.collect() - sage: 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: phi.parent() # optional - sage.rings.number_field + Set of field embeddings + from Number Field in a with defining polynomial x^2 + 5 + with a = 2.236067977499790?*I + to Complex Double Field """ if self._parent is None: D = self.domain() @@ -250,28 +260,31 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_convert_map_from(Q) + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # optional - 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 + sage: phi.domain # optional - sage.rings.number_field - sage: phi._make_strong_references() - sage: print(phi.domain) - The constant function (...) -> Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + sage: phi._make_strong_references() # optional - sage.rings.number_field + sage: print(phi.domain) # optional - 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: import gc sage: _ = gc.collect() - sage: C = Q.__class__.__base__ - sage: numberQuadFields = len([x for x in gc.get_objects() if isinstance(x, C)]) - sage: del Q, x + sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: numberQuadFields = len([x for x in gc.get_objects() # optional - sage.rings.number_field + ....: if isinstance(x, C)]) + sage: del Q, x # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + ....: if isinstance(x, C)]) True However, if we now make the references weak again, the number field can @@ -279,11 +292,12 @@ 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() + sage: phi._make_weak_references() # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + 1 + sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + ....: if isinstance(x, C)]) + 1 True - sage: phi + sage: phi # optional - sage.rings.number_field Defunct map """ if not isinstance(self.domain, ConstantFunction): @@ -311,28 +325,31 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_convert_map_from(Q) + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # optional - 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 + sage: phi.domain # optional - sage.rings.number_field - sage: phi._make_strong_references() - sage: print(phi.domain) - The constant function (...) -> Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + sage: phi._make_strong_references() # optional - sage.rings.number_field + sage: print(phi.domain) # optional - 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: import gc sage: _ = gc.collect() - sage: C = Q.__class__.__base__ - sage: numberQuadFields = len([x for x in gc.get_objects() if isinstance(x, C)]) - sage: del Q, x + sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: numberQuadFields = len([x for x in gc.get_objects() # optional - sage.rings.number_field + ....: if isinstance(x, C)]) + sage: del Q, x # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + ....: if isinstance(x, C)]) True However, if we now make the references weak again, the number field can @@ -340,17 +357,18 @@ 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() + sage: phi._make_weak_references() # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + 1 + sage: numberQuadFields == len([x for x in gc.get_objects() # optional - sage.rings.number_field + ....: if isinstance(x, C)]) + 1 True - sage: phi + sage: phi # optional - sage.rings.number_field Defunct map - sage: phi._make_strong_references() + sage: phi._make_strong_references() # optional - sage.rings.number_field Traceback (most recent call last): ... RuntimeError: The domain of this map became garbage collected - sage: phi.parent() + sage: phi.parent() # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: This map is in an invalid state, the domain has been garbage collected @@ -544,16 +562,16 @@ cdef class Map(Element): TESTS:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_coerce_map_from(Q); phi + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF._internal_coerce_map_from(Q); phi # optional - sage.rings.number_field (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 + sage: del Q # optional - sage.rings.number_field sage: import gc sage: _ = gc.collect() - sage: phi + sage: phi # optional - sage.rings.number_field Defunct map """ D = self.domain() @@ -704,7 +722,8 @@ cdef class Map(Element): sage: f(1/2) Traceback (most recent call last): ... - TypeError: 1/2 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 1/2 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented We test that the default call method really works as described above (that was fixed in :trac:`10496`):: @@ -746,11 +765,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)) # optional - sage.symbolic pushforward Symbolic Ring _call_ Rational Field 3 - sage: g(SR(3), exponent=2) # optional - sage.symbolic + sage: g(SR(3), exponent=2) # optional - sage.symbolic pushforward Symbolic Ring _call_with_args Rational Field 9 @@ -761,7 +780,8 @@ cdef class Map(Element): sage: h(2/3) Traceback (most recent call last): ... - TypeError: 2/3 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 2/3 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented """ P = parent(x) cdef Parent D = self.domain() @@ -1122,7 +1142,8 @@ cdef class Map(Element): sage: mor.extend_domain(ZZ['x']) Traceback (most recent call last): ... - TypeError: No coercion from Univariate Polynomial Ring in x over Integer Ring to Real Double Field + TypeError: No coercion from Univariate Polynomial Ring in x over Integer Ring + to Real Double Field """ D = self.domain() if D is None: @@ -1162,7 +1183,7 @@ cdef class Map(Element): Native morphism: From: Rational Field To: Real Double Field - sage: mor.extend_codomain(GF(7)) + sage: mor.extend_codomain(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: No coercion from Rational Field to Finite Field of size 7 @@ -1217,14 +1238,14 @@ cdef class Map(Element): ... TypeError: self must be an endomorphism - sage: K. = NumberField(x^4 - 5*x + 5) - sage: C5. = CyclotomicField(5) - sage: tau = K.hom([z - z^2]); tau + 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 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 + sage: tau^-1 # optional - sage.rings.number_field Ring morphism: From: Cyclotomic Field of order 5 and degree 4 To: Number Field in a with defining polynomial x^4 - 5*x + 5 @@ -1851,24 +1872,26 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: - 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) + 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 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()), phi1, phi2) - sage: c1.is_injective() + sage: c1 = FormalCompositeMap(Hom(QQ^1, V2, phi1.category_for()), # optional - sage.modules + ....: phi1, phi2) + sage: c1.is_injective() # optional - 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) - sage: c2 = FormalCompositeMap(Hom(V1, V1, phi2.category_for()), phi2, psi1) - sage: c2.is_injective() + 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 + ....: phi2, psi1) + sage: c2.is_injective() # optional - sage.modules Traceback (most recent call last): ... NotImplementedError: not enough information to deduce injectivity @@ -1876,17 +1899,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) - sage: c3 = FormalCompositeMap(Hom(V2, QQ^1, phi2.category_for()), psi2, psi1) - sage: c3.is_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 + ....: psi2, psi1) + sage: c3.is_injective() # optional - sage.modules False TESTS: Check that :trac:`23205` has been resolved:: - sage: f = QQ.hom(QQbar)*ZZ.hom(QQ) - sage: f.is_injective() + sage: f = QQ.hom(QQbar) * ZZ.hom(QQ) # optional - sage.rings.number_field + sage: f.is_injective() # optional - sage.rings.number_field True """ @@ -1923,33 +1947,38 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: sage: from sage.categories.map import FormalCompositeMap - sage: V3 = QQ^3 - sage: V2 = QQ^2 - sage: V1 = QQ^1 + sage: V3 = QQ^3 # optional - sage.modules + sage: V2 = QQ^2 # optional - sage.modules + sage: V1 = QQ^1 # optional - sage.modules If both maps are surjective, the composition is surjective:: - 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() + 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 + ....: phi32, phi21) + sage: c_phi.is_surjective() # optional - sage.modules True If the second map is not surjective, the composition is not surjective:: - sage: FormalCompositeMap(Hom(V3, V1, phi32.category_for()), phi32, V2.hom(Matrix([[0], [0]]), V1)).is_surjective() + sage: FormalCompositeMap(Hom(V3, V1, phi32.category_for()), # optional - sage.modules + ....: phi32, + ....: V2.hom(Matrix([[0], [0]]), V1)).is_surjective() False 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()), V2.hom(Matrix([[0], [0]]), V1), V1.hom(Matrix([[1]]), V1)).is_surjective() + sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # optional - 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()), + sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # optional - sage.modules ....: V2.hom(Matrix([[1, 1], [1, 1]]), V2), ....: V2.hom(Matrix([[1], [1]]), V1)).is_surjective() Traceback (most recent call last): @@ -1991,8 +2020,8 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: sage: f = QQ.coerce_map_from(ZZ) - sage: g = MatrixSpace(QQ, 2, 2).coerce_map_from(QQ) - sage: list((g*f).domains()) + sage: g = MatrixSpace(QQ, 2, 2).coerce_map_from(QQ) # optional - sage.modules + sage: list((g * f).domains()) # optional - sage.modules [Integer Ring, Rational Field] """ for f in self.__list: @@ -2026,9 +2055,9 @@ cdef class FormalCompositeMap(Map): of :class:`sage.rings.polynomial.polynomial_element.Polynomial` before (see comment there):: - sage: k = GF(47) - sage: R. = PolynomialRing(k) - sage: R.coerce_map_from(ZZ).section() + 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 Composite map: From: Univariate Polynomial Ring in x over Finite Field of size 47 To: Integer Ring @@ -2039,9 +2068,9 @@ cdef class FormalCompositeMap(Map): Lifting map: From: Finite Field of size 47 To: Integer Ring - sage: ZZ(R(45)) # indirect doctest + sage: ZZ(R(45)) # indirect doctest # optional - sage.rings.finite_rings 45 - sage: ZZ(3*x + 45) # indirect doctest + sage: ZZ(3*x + 45) # indirect doctest # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: not a constant polynomial diff --git a/src/sage/categories/modules.py b/src/sage/categories/modules.py index cb878f1c6f2..81f6df6f51f 100644 --- a/src/sage/categories/modules.py +++ b/src/sage/categories/modules.py @@ -72,10 +72,12 @@ class Modules(Category_module): Category of modules over Ring of integers modulo 9 sage: Modules(Integers(9)).super_categories() - [Category of bimodules over Ring of integers modulo 9 on the left and Ring of integers modulo 9 on the right] + [Category of bimodules over Ring of integers modulo 9 on the left + and Ring of integers modulo 9 on the right] sage: Modules(ZZ).super_categories() - [Category of bimodules over Integer Ring on the left and Integer Ring on the right] + [Category of bimodules over Integer Ring on the left + and Integer Ring on the right] sage: Modules == RingModules True @@ -162,7 +164,8 @@ def super_categories(self): EXAMPLES:: sage: Modules(ZZ).super_categories() - [Category of bimodules over Integer Ring on the left and Integer Ring on the right] + [Category of bimodules over Integer Ring on the left + and Integer Ring on the right] Nota bene:: @@ -204,7 +207,8 @@ def base_ring(self): EXAMPLES:: sage: C = Modules(QQ) & Semigroups(); C - Join of Category of semigroups and Category of vector spaces over Rational Field + Join of Category of semigroups + and Category of vector spaces over Rational Field sage: C.base_ring() Rational Field sage: C.base_ring.__module__ @@ -217,16 +221,16 @@ def base_ring(self): sage: C.base_ring.__module__ 'sage.categories.modules' - sage: C = DescentAlgebra(QQ,3).B().category() - sage: C.base_ring.__module__ + sage: C = DescentAlgebra(QQ,3).B().category() # optional - sage.combinat sage.modules + sage: C.base_ring.__module__ # optional - sage.combinat sage.modules 'sage.categories.modules' - sage: C.base_ring() + sage: C.base_ring() # optional - sage.combinat sage.modules Rational Field - sage: C = QuasiSymmetricFunctions(QQ).F().category() - sage: C.base_ring.__module__ + sage: C = QuasiSymmetricFunctions(QQ).F().category() # optional - sage.combinat sage.modules + sage: C.base_ring.__module__ # optional - sage.combinat sage.modules 'sage.categories.modules' - sage: C.base_ring() + sage: C.base_ring() # optional - sage.combinat sage.modules Rational Field """ for C in self.super_categories(): @@ -361,10 +365,11 @@ def FinitelyPresented(self): sage: Modules(ZZ).FinitelyPresented() Category of finitely presented modules over Integer Ring - sage: A = SteenrodAlgebra(2) - sage: from sage.modules.fp_graded.module import FPModule - sage: FPModule(A, [0, 1], [[Sq(2), Sq(1)]]).category() - Category of finitely presented graded modules over mod 2 Steenrod algebra, milnor basis + 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 + Category of finitely presented graded modules + over mod 2 Steenrod algebra, milnor basis TESTS:: @@ -516,7 +521,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()) + sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings True sage: Modules(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) False @@ -547,7 +552,8 @@ def extra_super_categories(self): sage: Modules(ZZ).FiniteDimensional().TensorProducts().extra_super_categories() [Category of finite dimensional modules over Integer Ring] sage: Modules(QQ).FiniteDimensional().TensorProducts().FiniteDimensional() - Category of tensor products of finite dimensional vector spaces over Rational Field + Category of tensor products of finite dimensional vector spaces + over Rational Field """ return [self.base_category()] @@ -565,7 +571,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()) + sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings True sage: Modules(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) False @@ -612,9 +618,9 @@ def linear_combination(self, iter_of_elements_coeff, factor_on_left=True): EXAMPLES:: - sage: m = matrix([[0,1],[1,1]]) - sage: J. = JordanAlgebra(m) - sage: J.linear_combination(((a+b, 1), (-2*b + c, -1))) + 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 1 + (3, -1) """ if factor_on_left: @@ -631,8 +637,8 @@ def tensor_square(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example() - sage: A.tensor_square() + sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups sage.modules + sage: A.tensor_square() # optional - 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 @@ -661,12 +667,14 @@ def module_morphism(self, *, function, category=None, codomain, **keywords): EXAMPLES:: - 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 - Generic endomorphism of 2-dimensional vector space over the Rational Field - sage: neg(e[0]) + sage: V = FiniteRankFreeModule(QQ, 2) # optional - sage.modules + sage: e = V.basis('e'); e # optional - sage.modules + 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 + Generic endomorphism of + 2-dimensional vector space over the Rational Field + sage: neg(e[0]) # optional - sage.modules Element -e_0 of the 2-dimensional vector space over the Rational Field """ @@ -698,11 +706,12 @@ def quotient(self, submodule, check=True, **kwds): EXAMPLES:: - sage: C = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: TA = TensorAlgebra(C) - sage: TA.quotient + sage: C = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: TA = TensorAlgebra(C) # optional - sage.modules + sage: TA.quotient # optional - sage.modules + Tensor Algebra of Free module generated by {'a', 'b', 'c'} + over Rational Field> """ return self.quotient_module(submodule, check=check, **kwds) @@ -748,21 +757,21 @@ def base_ring(self): EXAMPLES:: - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) - sage: H = Hom(E, F) - sage: H.base_ring() + 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 Integer Ring This ``base_ring`` method is actually overridden by :meth:`sage.structure.category_object.CategoryObject.base_ring`:: - sage: H.base_ring.__module__ + sage: H.base_ring.__module__ # optional - sage.modules Here we call it directly:: - sage: method = H.category().parent_class.base_ring - sage: method.__get__(H)() + sage: method = H.category().parent_class.base_ring # optional - sage.modules + sage: method.__get__(H)() # optional - sage.modules Integer Ring """ return self.domain().base_ring() @@ -772,24 +781,24 @@ def zero(self): """ EXAMPLES:: - 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 + 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 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)) + sage: f(E.monomial(2)) # optional - sage.modules 0 - sage: f(E.monomial(3)) == F.zero() + sage: f(E.monomial(3)) == F.zero() # optional - sage.modules True TESTS: We check that ``H.zero()`` is picklable:: - sage: loads(dumps(f.parent().zero())) + sage: loads(dumps(f.parent().zero())) # optional - 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 @@ -813,7 +822,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) + sage: End(ZZ^3) in Algebras(ZZ) # optional - sage.modules True """ from .magmatic_algebras import MagmaticAlgebras @@ -852,38 +861,46 @@ def __init_extra__(self): EXAMPLES:: - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) - sage: C = cartesian_product([E, F]); C + 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 Free module generated by {1, 2, 3} over Integer Ring (+) Free module generated by {2, 3, 4} over Integer Ring - sage: C.base_ring() + sage: C.base_ring() # optional - sage.modules Integer Ring Check that :trac:`29225` is fixed:: - sage: M = cartesian_product((ZZ^2, ZZ^3)); M - 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() - Category of Cartesian products of modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) - sage: M.base_ring() + sage: M = cartesian_product((ZZ^2, ZZ^3)); M # optional - 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 + 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 Integer Ring - sage: A = cartesian_product((QQ^2, QQ['x'])); A - The Cartesian product of (Vector space of dimension 2 over Rational Field, Univariate Polynomial Ring in x over Rational Field) - sage: A.category() - Category of Cartesian products of vector spaces over (number fields and quotient fields and metric spaces) - sage: A.base_ring() + sage: A = cartesian_product((QQ^2, QQ['x'])); A # optional - 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 + Category of Cartesian products of vector spaces + over (number fields and quotient fields and metric spaces) + sage: A.base_ring() # optional - 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 - The Cartesian product of (Univariate Polynomial Ring in x over Integer Ring, Vector space of dimension 3 over Rational Field) - sage: B.category() + sage: B = cartesian_product((ZZ['x'], QQ^3)); B # optional - 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 Category of Cartesian products of commutative additive groups - sage: B.base_ring() + sage: B.base_ring() # optional - sage.modules """ factors = self._sets if factors: @@ -899,10 +916,12 @@ def _lmul_(self, x): EXAMPLES:: - sage: A = FreeModule(ZZ, 2) - sage: B = cartesian_product([A, A]); B - 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])) + sage: A = FreeModule(ZZ, 2) # optional - sage.modules + sage: B = cartesian_product([A, A]); B # optional - 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 ((5, 10), (15, 20)) """ return self.parent()._cartesian_product_of_elements( @@ -934,9 +953,9 @@ def construction(self): EXAMPLES:: - sage: A = algebras.Free(QQ,2) - sage: T = A.tensor(A) - sage: T.construction() + 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 (The tensor functorial construction, (Free Algebra on 2 generators (None0, None1) over Rational Field, Free Algebra on 2 generators (None0, None1) over Rational Field)) @@ -957,20 +976,20 @@ def tensor_factors(self): EXAMPLES:: - 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 + 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 F # G - sage: T.tensor_factors() + sage: T.tensor_factors() # optional - sage.modules (F, G) TESTS:: - sage: M = CombinatorialFreeModule(ZZ, ((1, 1), (1, 2), (2, 1), (2, 2)), - ....: category=ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts()) - sage: M.construction() + 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 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 99b57ff8c8e..9f31917cf22 100644 --- a/src/sage/categories/modules_with_basis.py +++ b/src/sage/categories/modules_with_basis.py @@ -66,22 +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" - sage: Y = CombinatorialFreeModule(QQ, [3,4]); Y.__custom_name = "Y" - sage: H = Hom(X, Y); H - Set of Morphisms from X to Y in Category of finite dimensional vector spaces with basis over Rational Field + 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 + 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 + sage: H.zero() # todo: move this test into module once we have an example # optional - 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) - sage: H.zero()(x) + sage: x = X.monomial(1) + 3 * X.monomial(2) # optional - sage.modules + sage: H.zero()(x) # optional - sage.modules 0 EXAMPLES: @@ -89,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 + sage: phi = H(on_basis=lambda i: Y.monomial(i + 2)); phi # optional - sage.modules Generic morphism: From: X To: Y - sage: phi(x) + sage: phi(x) # optional - sage.modules B[3] + 3*B[4] We can retrieve the function acting on indices of the basis:: - sage: f = phi.on_basis() - sage: f(1), f(2) + sage: f = phi.on_basis() # optional - sage.modules + sage: f(1), f(2) # optional - sage.modules (B[3], B[4]) `Hom(X,Y)` has a natural module structure (except for the zero, @@ -108,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) + sage: H in ModulesWithBasis(QQ), H in Modules(QQ) # optional - sage.modules (False, True) Some more playing around with categories and higher order homsets:: - sage: H.category() + sage: H.category() # optional - sage.modules Category of homsets of modules with basis over Rational Field - sage: Hom(H, H).category() + sage: Hom(H, H).category() # optional - sage.modules Category of endsets of homsets of modules with basis over Rational Field .. TODO:: ``End(X)`` is an algebra. @@ -128,10 +129,10 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): TESTS:: - sage: f = H.zero().on_basis() - sage: f(1) + sage: f = H.zero().on_basis() # optional - sage.modules + sage: f(1) # optional - sage.modules 0 - sage: f(2) + sage: f(2) # optional - sage.modules 0 sage: TestSuite(ModulesWithBasis(ZZ)).run() @@ -151,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'))) + sage: CZ(CombinatorialFreeModule(ZZ, ('a', 'b', 'c'))) # optional - sage.modules Free module generated by {'a', 'b', 'c'} over Integer Ring - sage: CZ(ZZ^3) + sage: CZ(ZZ^3) # optional - 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 + sage: CQ(ZZ^3) # indirect doctest # optional - 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 + sage: CQ(AbelianVariety(Gamma0(37))) # indirect doctest # optional - sage.modules Vector space of dimension 4 over Rational Field """ try: @@ -209,14 +210,14 @@ def basis(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: F.basis() + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.basis() # optional - sage.modules Finite family {'a': B['a'], 'b': B['b'], 'c': B['c']} :: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) - sage: list(QS3.basis()) + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.group sage.modules + sage: list(QS3.basis()) # optional - sage.group 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 @@ -297,14 +298,16 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") - sage: phi = X.module_morphism(lambda i: Y.monomial(i) + 2*Y.monomial(i+1), codomain = Y) - sage: x = X.basis(); y = Y.basis() - sage: phi(x[1] + x[3]) + 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: 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 B[1] + 2*B[2] + B[3] + 2*B[4] - sage: phi + sage: phi # optional - sage.modules Generic morphism: From: X To: Y @@ -315,101 +318,105 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, ``CommutativeAdditiveMonoids()`` that contains both the domain and the codomain:: - sage: phi.category_for() - Category of finite dimensional vector spaces with basis over Rational Field + sage: phi.category_for() # optional - sage.modules + Category of finite dimensional vector spaces with basis + over Rational Field With the ``zero`` argument, one can define affine morphisms:: - sage: phi = X.module_morphism(lambda i: Y.monomial(i) + 2*Y.monomial(i+1), - ....: codomain = Y, zero = 10*y[1]) - sage: phi(x[1] + x[3]) + 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 11*B[1] + 2*B[2] + B[3] + 2*B[4] In this special case, the default category is ``Sets()``:: - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of sets One can construct morphisms with the base ring as codomain:: - 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) ) + 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 -1 - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (ZZ is currently not in Modules(ZZ)) + sage: phi.category_for() # todo: not implemented (ZZ is currently not in Modules(ZZ)) # optional - sage.modules 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 ) - sage: phi( 2 * X.monomial(1) + 3 * X.monomial(-1) ) + 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 -1.00000000000000 - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (RR is currently not in Modules(ZZ)) + sage: phi.category_for() # todo: not implemented (RR is currently not in Modules(ZZ)) # optional - sage.modules Category of modules over Integer Ring - sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=Zmod(4) ) - sage: phi( 2 * X.monomial(1) + 3 * X.monomial(-1) ) + 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 3 - sage: phi = Y.module_morphism(on_basis=lambda i: i, codomain=Zmod(4) ) + sage: phi = Y.module_morphism(on_basis=lambda i: i, codomain=Zmod(4)) # optional - sage.modules Traceback (most recent call last): ... - ValueError: codomain(=Ring of integers modulo 4) should be a module over the base ring of the domain(=Y) + ValueError: codomain(=Ring of integers modulo 4) should be a module + over the base ring of the domain(=Y) On can also define module morphisms between free modules over different base rings; here we implement the natural map from `X = \RR^2` to `Y = \CC`:: - 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 ): + 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 ....: 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 ) - sage: v = 3 * x + 2 * y; v + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - sage.modules + sage: v = 3 * x + 2 * y; v # optional - sage.modules 3.00000000000000*B['x'] + 2.00000000000000*B['y'] - sage: phi(v) + sage: phi(v) # optional - sage.modules (3.00000000000000+2.00000000000000*I)*B['z'] - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (CC is currently not in Modules(RR)!) + sage: phi.category_for() # todo: not implemented (CC is currently not in Modules(RR)!) # optional - sage.modules Category of vector spaces over Real Field with 53 bits of precision - 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) + 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 (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']) - sage: phi = X.module_morphism( on_basis=on_basis, codomain=Y ) + sage: Y = CombinatorialFreeModule(QQ, ['z']) # optional - sage.modules + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - 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) + 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']) - sage: phi = Y.module_morphism( on_basis=on_basis, codomain=X ) + sage: Y = CombinatorialFreeModule(RR['q'], ['z']) # optional - sage.modules + sage: phi = Y.module_morphism(on_basis=on_basis, codomain=X) # optional - sage.modules Traceback (most recent call last): ... - ValueError: codomain(=Free module generated by {'x', 'y'} over Real Field with 53 bits of precision) - should be a module over the base ring of the - domain(=Free module generated by {'z'} over Univariate Polynomial Ring in q over Real Field with 53 bits of precision) + ValueError: codomain(=Free module generated by {'x', 'y'} + over Real Field with 53 bits of precision) should be a module over + the base ring of the domain(=Free module generated by {'z'} over + Univariate Polynomial Ring in q over Real Field with 53 bits of precision) With the ``diagonal=d`` argument, this constructs the @@ -422,11 +429,11 @@ 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") - 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]) + 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 (B[1], 2*B[2], 6*B[3]) See also: :class:`sage.modules.with_basis.morphism.DiagonalModuleMorphism`. @@ -435,13 +442,15 @@ 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"); x = X.basis() - sage: Y = CombinatorialFreeModule(ZZ, [3,4]); Y.rename("Y"); 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]) + 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 3*B[4] - sage: phi(x[2]) + sage: phi(x[2]) # optional - sage.modules B[3] + 5*B[4] @@ -454,35 +463,36 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, preimages and to invert the morphism:: sage: I = list(range(1, 200)) - 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]) + 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 B[1] + B[2] - sage: phi(x[6]) + sage: phi(x[6]) # optional - sage.modules B[1] + B[2] + B[3] + B[6] - sage: phi(x[30]) + sage: phi(x[30]) # optional - sage.modules B[1] + B[2] + B[3] + B[5] + B[6] + B[10] + B[15] + B[30] - sage: phi.preimage(y[2]) + sage: phi.preimage(y[2]) # optional - sage.modules -B[1] + B[2] - sage: phi.preimage(y[6]) + sage: phi.preimage(y[6]) # optional - sage.modules B[1] - B[2] - B[3] + B[6] - sage: phi.preimage(y[30]) + sage: phi.preimage(y[30]) # optional - sage.modules -B[1] + B[2] + B[3] + B[5] - B[6] - B[10] - B[15] + B[30] - sage: (phi^-1)(y[30]) + sage: (phi^-1)(y[30]) # optional - sage.modules -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() - 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]) + 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 + ....: triangular="upper") + sage: phi(x[2] + 3*x[4]) # optional - sage.modules 4*B[0] + B[2] + 3*B[4] - sage: phi.preimage(_) + sage: phi.preimage(_) # optional - sage.modules B[2] + 3*B[4] For details and further optional arguments, see @@ -505,8 +515,8 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, TESTS:: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(codomain=X) + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: phi = X.module_morphism(codomain=X) # optional - sage.modules Traceback (most recent call last): ... ValueError: module_morphism() takes exactly one option @@ -514,8 +524,9 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(diagonal=factorial, matrix=matrix(), codomain=X) + 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 + ....: codomain=X) Traceback (most recent call last): ... ValueError: module_morphism() takes exactly one option @@ -523,16 +534,16 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(matrix=factorial, codomain=X) + 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 Traceback (most recent call last): ... ValueError: matrix (=...factorial...) should be a matrix :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(diagonal=3, codomain=X) + 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 Traceback (most recent call last): ... ValueError: diagonal (=3) should be a function @@ -571,20 +582,20 @@ def _repr_(self): """ EXAMPLES:: - sage: class FooBar(CombinatorialFreeModule): pass - sage: C = FooBar(QQ, (1,2,3)); C # indirect doctest + sage: class FooBar(CombinatorialFreeModule): pass # optional - sage.modules + sage: C = FooBar(QQ, (1,2,3)); C # indirect doctest # optional - sage.modules Free module generated by {1, 2, 3} over Rational Field - sage: C._name = "foobar"; C + sage: C._name = "foobar"; C # optional - sage.modules foobar over Rational Field - sage: C.rename("barfoo"); C + sage: C.rename("barfoo"); C # optional - sage.modules barfoo sage: class FooBar(Parent): - ....: def basis(self): return Family({1:"foo", 2:"bar"}) + ....: def basis(self): return Family({1: "foo", 2: "bar"}) ....: def base_ring(self): return QQ - sage: FooBar(category = ModulesWithBasis(QQ)) + sage: FooBar(category=ModulesWithBasis(QQ)) Free module generated by [1, 2] over Rational Field """ if hasattr(self, "_name"): @@ -608,26 +619,28 @@ def _compute_support_order(self, elements, support_order=None): A finite dimensional module:: - 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) + 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 + ....: B[2], B[3], B[1] + B[2] + B[8]] + sage: V._compute_support_order(elts) # optional - sage.modules (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]) + sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) # optional - sage.modules (1, 2, 0, 4, 3, 5, 9, 8, 7, 6) - sage: V._compute_support_order(elts, lambda x: -x) + sage: V._compute_support_order(elts, lambda x: -x) # optional - sage.modules (8, 5, 3, 2, 1, 0) An infinite dimensional module:: - 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) + 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 + ....: B[2], B[3], B[1] + B[2] + B[8]] + sage: V._compute_support_order(elts) # optional - sage.modules (0, 1, 2, 3, 5, 8) - sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) + sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) # optional - sage.modules (1, 2, 0, 4, 3, 5, 9, 8, 7, 6) - sage: V._compute_support_order(elts, lambda x: -x) + sage: V._compute_support_order(elts, lambda x: -x) # optional - sage.modules (8, 5, 3, 2, 1, 0) """ if support_order is None: @@ -672,17 +685,17 @@ def echelon_form(self, elements, row_reduced=False, order=None): EXAMPLES:: sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, ZZ, prefix='z') - sage: z = C.basis() - sage: C.echelon_form([z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]]) + 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 [z[0] - z[2], z[1] - z[2]] TESTS: We convert the input elements to ``self``:: - sage: s = SymmetricFunctions(QQ).s() - sage: s.echelon_form([1, s[1] + 5]) + sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat sage.modules + sage: s.echelon_form([1, s[1] + 5]) # optional - sage.combinat sage.modules [s[], s[1]] """ # Make sure elements consists of elements of ``self`` @@ -751,21 +764,21 @@ 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") - sage: x = X.basis() - sage: gens = [x[0] - x[1], x[1] - x[2]]; gens + 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 [x[0] - x[1], x[1] - x[2]] - sage: Y = X.submodule(gens, already_echelonized=True) - sage: Y.print_options(prefix='y'); Y + sage: Y = X.submodule(gens, already_echelonized=True) # optional - sage.modules + sage: Y.print_options(prefix='y'); Y # optional - sage.modules Free module generated by {0, 1} over Rational Field - sage: y = Y.basis() - sage: y[1] + sage: y = Y.basis() # optional - sage.modules + sage: y[1] # optional - sage.modules y[1] - sage: y[1].lift() + sage: y[1].lift() # optional - sage.modules x[1] - x[2] - sage: Y.retract(x[0]-x[2]) + sage: Y.retract(x[0] - x[2]) # optional - sage.modules y[0] + y[1] - sage: Y.retract(x[0]) + sage: Y.retract(x[0]) # optional - sage.modules Traceback (most recent call last): ... ValueError: x[0] is not in the image @@ -773,23 +786,23 @@ 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") - sage: x = X.basis() - sage: gens = Family({1 : x[0] - x[1], 3: x[1] - x[2]}); gens + 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 Finite family {1: x[0] - x[1], 3: x[1] - x[2]} - sage: Y = X.submodule(gens, already_echelonized=True) - sage: Y.print_options(prefix='y'); Y + sage: Y = X.submodule(gens, already_echelonized=True) # optional - sage.modules + sage: Y.print_options(prefix='y'); Y # optional - sage.modules Free module generated by {1, 3} over Rational Field - sage: y = Y.basis() - sage: y[1] + sage: y = Y.basis() # optional - sage.modules + sage: y[1] # optional - sage.modules y[1] - sage: y[1].lift() + sage: y[1].lift() # optional - sage.modules x[0] - x[1] - sage: y[3].lift() + sage: y[3].lift() # optional - sage.modules x[1] - x[2] - sage: Y.retract(x[0]-x[2]) + sage: Y.retract(x[0] - x[2]) # optional - sage.modules y[1] + y[3] - sage: Y.retract(x[0]) + sage: Y.retract(x[0]) # optional - sage.modules Traceback (most recent call last): ... ValueError: x[0] is not in the image @@ -797,55 +810,56 @@ 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") - sage: x = X.basis() - sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]; gens + 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 [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] - sage: Y = X.submodule(gens, already_echelonized=False) - sage: Y.print_options(prefix='y') - sage: Y + 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 Free module generated by {0, 1} over Rational Field - sage: [b.lift() for b in Y.basis()] + sage: [b.lift() for b in Y.basis()] # optional - sage.modules [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) - sage: S3A = S3.algebra(QQ) - sage: basis = S3A.annihilator_basis(S3A.algebra_generators(), S3A.bracket) - sage: basis + 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 + ....: S3A.bracket) + sage: basis # optional - sage.groups sage.modules ((), (1,2,3) + (1,3,2), (2,3) + (1,2) + (1,3)) - sage: center = S3A.submodule(basis, - ....: category=AlgebrasWithBasis(QQ).Subobjects(), - ....: already_echelonized=True) - sage: center + sage: center = S3A.submodule(basis, # optional - sage.groups sage.modules + ....: category=AlgebrasWithBasis(QQ).Subobjects(), + ....: already_echelonized=True) + sage: center # optional - sage.groups sage.modules Free module generated by {0, 1, 2} over Rational Field - sage: center in Algebras + sage: center in Algebras # optional - sage.groups sage.modules True - sage: center.print_options(prefix='c') - sage: c = center.basis() - sage: c[1].lift() + 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 (1,2,3) + (1,3,2) - sage: c[0]^2 + sage: c[0]^2 # optional - sage.groups sage.modules c[0] - sage: e = 1/6*(c[0]+c[1]+c[2]) - sage: e.is_idempotent() + sage: e = 1/6 * (c[0]+c[1]+c[2]) # optional - sage.groups sage.modules + sage: e.is_idempotent() # optional - sage.groups sage.modules True Of course, this center is best constructed using:: - sage: center = S3A.center() + sage: center = S3A.center() # optional - sage.groups sage.modules We can also automatically construct a basis such that the lift morphism is (lower) unitriangular:: sage: R. = QQ[] - 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() + 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 [ 1 0] [ 0 1] [-1 -1] @@ -853,17 +867,17 @@ 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') - 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()] + 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 [z[0] - z[2], z[1] - z[2]] TESTS:: - sage: TestSuite(Y).run() - sage: TestSuite(center).run() + sage: TestSuite(Y).run() # optional - sage.modules + sage: TestSuite(center).run() # optional - sage.groups sage.modules """ # Make sure gens consists of elements of ``self`` from sage.sets.family import Family, AbstractFamily @@ -906,24 +920,25 @@ def quotient_module(self, submodule, check=True, already_echelonized=False, cate EXAMPLES:: - 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 + 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 + ....: already_echelonized=True) + sage: Y.print_options(prefix='y'); Y # optional - sage.modules Free module generated by {2} over Rational Field - sage: y = Y.basis() - sage: y[2] + sage: y = Y.basis() # optional - sage.modules + sage: y[2] # optional - sage.modules y[2] - sage: y[2].lift() + sage: y[2].lift() # optional - sage.modules x[2] - sage: Y.retract(x[0]+2*x[1]) + sage: Y.retract(x[0] + 2*x[1]) # optional - sage.modules 3*y[2] sage: R. = QQ[] - 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) + 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 .. SEEALSO:: @@ -945,10 +960,10 @@ def tensor(*parents, **kwargs): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example(); A.rename("A") - sage: A.tensor(A,A) + sage: A = C.example(); A.rename("A") # optional - sage.combinat sage.modules + sage: A.tensor(A, A) # optional - sage.combinat sage.modules A # A # A - sage: A.rename(None) + sage: A.rename(None) # optional - sage.combinat sage.modules """ constructor = kwargs.pop('constructor', tensor) cat = constructor.category_from_parents(parents) @@ -960,24 +975,24 @@ def cardinality(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: S.cardinality() + sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S.cardinality() # optional - sage.groups sage.modules +Infinity - sage: S = SymmetricGroupAlgebra(GF(2), 4) # not tested -- MRO bug trac #15475 - sage: S.cardinality() # not tested -- MRO bug trac #15475 + 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 16777216 - sage: S.cardinality().factor() # not tested -- MRO bug trac #15475 + sage: S.cardinality().factor() # not tested -- MRO bug trac #15475 # optional - sage.groups sage.rings.finite_rings sage.modules 2^24 - sage: E. = ExteriorAlgebra(QQ) - sage: E.cardinality() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: E.cardinality() # optional - sage.combinat sage.modules +Infinity - sage: E. = ExteriorAlgebra(GF(3)) - sage: E.cardinality() + 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 81 - sage: s = SymmetricFunctions(GF(2)).s() - sage: s.cardinality() + 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 +Infinity """ from sage.rings.infinity import Infinity @@ -994,11 +1009,11 @@ def is_finite(self): EXAMPLES:: - sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() + sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() # optional - sage.groups sage.modules True - sage: GroupAlgebra(SymmetricGroup(2)).is_finite() + sage: GroupAlgebra(SymmetricGroup(2)).is_finite() # optional - sage.groups sage.modules False - sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite() + sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite() # optional - sage.groups sage.modules False """ return (self.base_ring().is_finite() and self.group().is_finite()) @@ -1013,14 +1028,15 @@ def monomial(self, i): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.monomial('a') + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.monomial('a') # optional - sage.modules B['a'] ``F.monomial`` is in fact (almost) a map:: - sage: F.monomial - Term map from {'a', 'b', 'c'} to Free module generated by {'a', 'b', 'c'} over Rational Field + sage: F.monomial # optional - sage.modules + Term map from {'a', 'b', 'c'} + to Free module generated by {'a', 'b', 'c'} over Rational Field """ return self.basis()[i] @@ -1029,8 +1045,8 @@ def _sum_of_monomials(self, indices): TESTS:: sage: R. = QQ[] - sage: W = DifferentialWeylAlgebra(R) - sage: W._sum_of_monomials([((1,0), (1,0)), ((0,0), (0,1))]) + 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 dy + x*dx """ # This is the generic implementation. When implementing a @@ -1051,16 +1067,16 @@ def sum_of_monomials(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.sum_of_monomials(['a', 'b']) + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.sum_of_monomials(['a', 'b']) # optional - sage.modules B['a'] + B['b'] - sage: F.sum_of_monomials(['a', 'b', 'a']) + sage: F.sum_of_monomials(['a', 'b', 'a']) # optional - sage.modules 2*B['a'] + B['b'] ``F.sum_of_monomials`` is in fact (almost) a map:: - sage: F.sum_of_monomials + sage: F.sum_of_monomials # optional - sage.modules A map to Free module generated by {'a', 'b', 'c'} over Rational Field """ # domain = iterables of basis indices of self. @@ -1070,10 +1086,10 @@ def monomial_or_zero_if_none(self, i): """ EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.monomial_or_zero_if_none('a') + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.monomial_or_zero_if_none('a') # optional - sage.modules B['a'] - sage: F.monomial_or_zero_if_none(None) + sage: F.monomial_or_zero_if_none(None) # optional - sage.modules 0 """ if i is None: @@ -1095,9 +1111,9 @@ def term(self, index, coeff=None): EXAMPLES:: - sage: m = matrix([[0,1],[1,1]]) - sage: J. = JordanAlgebra(m) - sage: J.term(1, -2) + 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 0 + (-2, 0) Design: should this do coercion on the coefficient ring? @@ -1121,9 +1137,9 @@ def sum_of_terms(self, terms): EXAMPLES:: - sage: m = matrix([[0,1],[1,1]]) - sage: J. = JordanAlgebra(m) - sage: J.sum_of_terms([(0, 2), (2, -3)]) + 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 2 + (0, -3) """ return self.sum(self.term(index, coeff) for (index, coeff) in terms) @@ -1150,21 +1166,21 @@ def _apply_module_morphism(self, x, on_basis, codomain=False): EXAMPLES:: - 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 + 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 6 - sage: s._apply_module_morphism(b, f) #2*(1+2+3) + sage: s._apply_module_morphism(b, f) #2*(1+2+3) # optional - sage.combinat sage.modules 12 - sage: s._apply_module_morphism(s(0), f) + sage: s._apply_module_morphism(s(0), f) # optional - sage.combinat sage.modules 0 - sage: s._apply_module_morphism(s(1), f) + sage: s._apply_module_morphism(s(1), f) # optional - sage.combinat sage.modules 0 - sage: s._apply_module_morphism(s(1), lambda part: len(part), ZZ) + sage: s._apply_module_morphism(s(1), lambda part: len(part), ZZ) # optional - sage.combinat sage.modules 0 - sage: s._apply_module_morphism(s(1), lambda part: len(part)) + sage: s._apply_module_morphism(s(1), lambda part: len(part)) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: codomain could not be determined @@ -1206,9 +1222,9 @@ def _apply_module_endomorphism(self, x, on_basis): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).schur() - sage: f = lambda part: 2*s(part.conjugate()) - sage: s._apply_module_endomorphism( s([2,1]) + s([1,1,1]), f) + 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 2*s[2, 1] + 2*s[3] """ mc = x.monomial_coefficients(copy=False) @@ -1221,8 +1237,8 @@ def dimension(self): EXAMPLES:: - sage: A. = algebras.DifferentialWeyl(QQ) - sage: A.dimension() + sage: A. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules + sage: A.dimension() # optional - sage.combinat sage.modules +Infinity """ try: @@ -1242,17 +1258,17 @@ def _from_dict(self, d, coerce=True, remove_zeros=True): EXAMPLES:: - sage: A. = algebras.DifferentialWeyl(QQ) - sage: K = A.basis().keys() - sage: d = {K[0]: 3, K[12]: -4/3} - sage: A._from_dict(d) + 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 -4/3*dx^2 + 3 sage: R. = QQ[] - sage: d = {K[0]: y, K[12]: -4/3} - sage: A._from_dict(d, coerce=False) + 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 -4/3*dx^2 + y - sage: A._from_dict(d, coerce=True) + sage: A._from_dict(d, coerce=True) # optional - sage.combinat sage.modules Traceback (most recent call last): ... TypeError: not a constant polynomial @@ -1291,21 +1307,21 @@ def random_element(self, n=2): EXAMPLES:: - sage: x = DihedralGroup(6).algebra(QQ).random_element() - sage: x.parent() is DihedralGroup(6).algebra(QQ) + 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 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) + sage: libgap.set_seed(0) # optional - sage.libs.gap 0 - sage: m = SU(2, 13).algebra(QQ).random_element(1) - sage: m.parent() is SU(2, 13).algebra(QQ) + 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 True - sage: p = CombinatorialFreeModule(ZZ, Partitions(4)).random_element() - sage: p.parent() is CombinatorialFreeModule(ZZ, Partitions(4)) + 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 True TESTS: @@ -1315,17 +1331,16 @@ 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): + sage: class Foo(CombinatorialFreeModule): # optional - sage.modules ....: def _element_constructor_(self,x): ....: if x in self: ....: return x ....: else: ....: raise ValueError - sage: from sage.categories.magmatic_algebras \ - ....: import MagmaticAlgebras + sage: from sage.categories.magmatic_algebras import MagmaticAlgebras sage: C = MagmaticAlgebras(QQ).WithBasis().Unital() - sage: F = Foo(QQ, tuple(), category=C) - sage: F.random_element() == F.zero() + sage: F = Foo(QQ, tuple(), category=C) # optional - sage.modules + sage: F.random_element() == F.zero() # optional - sage.modules True """ @@ -1365,25 +1380,25 @@ def monomial_coefficients(self, copy=True): EXAMPLES:: - 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'] + 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 1 - sage: d['c'] + sage: d['c'] # optional - sage.modules 3 TESTS: We check that we make a copy of the coefficient dictionary:: - 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 + 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 B['a'] + 3*B['c'] """ @@ -1393,10 +1408,10 @@ def __getitem__(self, m): EXAMPLES:: - sage: W. = DifferentialWeylAlgebra(QQ) - sage: x[((0,0,0),(0,0,0))] + sage: W. = DifferentialWeylAlgebra(QQ) # optional - sage.combinat sage.modules + sage: x[((0,0,0), (0,0,0))] # optional - sage.combinat sage.modules 0 - sage: x[((1,0,0),(0,0,0))] + sage: x[((1,0,0), (0,0,0))] # optional - sage.combinat sage.modules 1 """ res = self.monomial_coefficients(copy=False).get(m) @@ -1422,19 +1437,19 @@ def coefficient(self, m): EXAMPLES:: - sage: s = CombinatorialFreeModule(QQ, Partitions()) - sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1]) - sage: z.coefficient([4]) + 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 1 - sage: z.coefficient([2,1]) + sage: z.coefficient([2,1]) # optional - sage.combinat sage.modules -2 - sage: z.coefficient(Partition([2,1])) + sage: z.coefficient(Partition([2,1])) # optional - sage.combinat sage.modules -2 - sage: z.coefficient([1,2]) + sage: z.coefficient([1,2]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [1, 2] should be an element of Partitions - sage: z.coefficient(Composition([2,1])) + sage: z.coefficient(Composition([2,1])) # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [2, 1] should be an element of Partitions @@ -1442,12 +1457,12 @@ def coefficient(self, m): Test that ``coefficient`` also works for those parents that do not have an ``element_class``:: - sage: H = pAdicWeightSpace(3) - sage: F = CombinatorialFreeModule(QQ, H) - sage: hasattr(H, "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 False - sage: h = H.an_element() - sage: (2*F.monomial(h)).coefficient(h) + sage: h = H.an_element() # optional - sage.modules sage.rings.padics + sage: (2*F.monomial(h)).coefficient(h) # optional - sage.modules sage.rings.padics 2 """ # NT: coefficient_fast should be the default, just with appropriate assertions @@ -1465,22 +1480,22 @@ def is_zero(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: f.is_zero() + 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 False - sage: F.zero().is_zero() + sage: F.zero().is_zero() # optional - sage.modules True :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s([2,1]).is_zero() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: s([2,1]).is_zero() # optional - sage.combinat sage.modules False - sage: s(0).is_zero() + sage: s(0).is_zero() # optional - sage.combinat sage.modules True - sage: (s([2,1]) - s([2,1])).is_zero() + sage: (s([2,1]) - s([2,1])).is_zero() # optional - sage.combinat sage.modules True """ zero = self.parent().base_ring().zero() @@ -1493,17 +1508,17 @@ def __len__(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: len(f) + 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 2 :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: len(z) + 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 4 """ return len(self.support()) @@ -1515,17 +1530,17 @@ def length(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: f.length() + 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 2 :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: z.length() + 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 4 """ return len(self) @@ -1540,17 +1555,17 @@ def support(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: sorted(f.support()) + 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 ['a', 'c'] :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: sorted(z.support()) + 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 [[1], [1, 1, 1], [2, 1], [4]] """ try: @@ -1578,13 +1593,13 @@ def monomials(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] + 2*B['c'] - sage: f.monomials() + 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 [B['a'], B['c']] - sage: (F.zero()).monomials() + sage: (F.zero()).monomials() # optional - sage.modules [] """ P = self.parent() @@ -1599,10 +1614,10 @@ def terms(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] + 2*B['c'] - sage: f.terms() + 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 [B['a'], 2*B['c']] """ P = self.parent() @@ -1627,20 +1642,20 @@ def coefficients(self, sort=True): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: f.coefficients() + 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 [1, -3] - sage: f = B['c'] - 3*B['a'] - sage: f.coefficients() + sage: f = B['c'] - 3*B['a'] # optional - sage.modules + sage: f.coefficients() # optional - sage.modules [-3, 1] :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: z.coefficients() + 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 [1, 1, 1, 1] """ zero = self.parent().base_ring().zero() @@ -1659,15 +1674,15 @@ def support_of_term(self): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") - sage: X.monomial(2).support_of_term() + sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") # optional - sage.modules + sage: X.monomial(2).support_of_term() # optional - sage.modules 2 - sage: X.term(3, 2).support_of_term() + sage: X.term(3, 2).support_of_term() # optional - sage.modules 3 An exception is raised if ``self`` has more than one term:: - sage: (X.monomial(2) + X.monomial(3)).support_of_term() + sage: (X.monomial(2) + X.monomial(3)).support_of_term() # optional - sage.modules Traceback (most recent call last): ... ValueError: B[2] + B[3] is not a single term @@ -1689,18 +1704,18 @@ def leading_support(self, *args, **kwds): EXAMPLES:: - 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() + 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 3 - sage: def key(x): return -x - sage: x.leading_support(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_support(key=key) # optional - sage.modules 1 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_support() + 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 [3] """ return max(self.support(), *args, **kwds) @@ -1724,17 +1739,17 @@ def leading_item(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) - sage: x.leading_item() + 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 (3, 4) - sage: def key(x): return -x - sage: x.leading_item(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_item(key=key) # optional - sage.modules (1, 3) - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_item() + 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 ([3], -5) """ k = self.leading_support(*args, **kwds) @@ -1753,17 +1768,17 @@ def leading_monomial(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.leading_monomial() + 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 B[3] - sage: def key(x): return -x - sage: x.leading_monomial(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_monomial(key=key) # optional - sage.modules B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_monomial() + 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 s[3] """ return self.parent().monomial(self.leading_support(*args, **kwds)) @@ -1781,17 +1796,17 @@ def leading_coefficient(self, *args, **kwds): EXAMPLES:: - 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() + 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 1 - sage: def key(x): return -x - sage: x.leading_coefficient(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_coefficient(key=key) # optional - sage.modules 3 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_coefficient() + 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 -5 """ return self.leading_item(*args, **kwds)[1] @@ -1809,17 +1824,17 @@ def leading_term(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.leading_term() + 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 B[3] - sage: def key(x): return -x - sage: x.leading_term(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_term(key=key) # optional - sage.modules 3*B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_term() + 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 -5*s[3] """ return self.parent().term(*self.leading_item(*args, **kwds)) @@ -1835,18 +1850,18 @@ def trailing_support(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) - sage: x.trailing_support() + 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 1 - sage: def key(x): return -x - sage: x.trailing_support(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_support(key=key) # optional - sage.modules 3 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_support() + 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 [1] """ return min(self.support(), *args, **kwds) @@ -1865,17 +1880,17 @@ def trailing_item(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_item() + 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 (1, 3) - sage: def key(x): return -x - sage: x.trailing_item(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_item(key=key) # optional - sage.modules (3, 1) - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_item() + 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 ([1], 2) """ k = self.trailing_support(*args, **kwds) @@ -1894,17 +1909,17 @@ def trailing_monomial(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_monomial() + 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 B[1] - sage: def key(x): return -x - sage: x.trailing_monomial(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_monomial(key=key) # optional - sage.modules B[3] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_monomial() + 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 s[1] """ return self.parent().monomial(self.trailing_support(*args, **kwds)) @@ -1922,17 +1937,17 @@ def trailing_coefficient(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_coefficient() + 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 3 - sage: def key(x): return -x - sage: x.trailing_coefficient(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_coefficient(key=key) # optional - sage.modules 1 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_coefficient() + 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 2 """ return self.trailing_item(*args, **kwds)[1] @@ -1950,17 +1965,17 @@ def trailing_term(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_term() + 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 3*B[1] - sage: def key(x): return -x - sage: x.trailing_term(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_term(key=key) # optional - sage.modules B[3] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_term() + 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 2*s[1] """ return self.parent().term(*self.trailing_item(*args, **kwds)) @@ -1979,24 +1994,24 @@ def map_coefficients(self, f): EXAMPLES:: - 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) + 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 6*B['a'] + 2*B['c'] Killed coefficients are handled properly:: - sage: f.map_coefficients(lambda x: 0) + sage: f.map_coefficients(lambda x: 0) # optional - sage.modules 0 - sage: list(f.map_coefficients(lambda x: 0)) + sage: list(f.map_coefficients(lambda x: 0)) # optional - sage.modules [] :: - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1])+2*s([3,2]) - sage: a.map_coefficients(lambda x: x*2) + 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 2*s[2, 1] + 4*s[3, 2] """ return self.parent().sum_of_terms( (m, f(c)) for m,c in self ) @@ -2015,30 +2030,30 @@ def map_support(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) - sage: x = B.an_element(); x + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules + sage: x = B.an_element(); x # optional - sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_support(lambda i: -i) + sage: x.map_support(lambda i: -i) # optional - sage.modules 3*B[-1] + 2*B[0] + 2*B[1] ``f`` needs not be injective:: - sage: x.map_support(lambda i: 1) + sage: x.map_support(lambda i: 1) # optional - sage.modules 7*B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1])+2*s([3,2]) - sage: a.map_support(lambda x: x.conjugate()) + 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 s[2, 1] + 2*s[2, 2, 1] TESTS:: - sage: B.zero() # This actually failed at some point!!! See #8890 + sage: B.zero() # This actually failed at some point!!! See #8890 # optional - sage.modules 0 - sage: y = B.zero().map_support(lambda i: i/0); y + sage: y = B.zero().map_support(lambda i: i/0); y # optional - sage.modules 0 - sage: y.parent() is B + sage: y.parent() is B # optional - sage.modules True """ return self.parent().sum_of_terms( (f(m), c) for m,c in self ) @@ -2057,22 +2072,22 @@ def map_support_skip_none(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) - sage: x = B.an_element(); x + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules + sage: x = B.an_element(); x # optional - sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_support_skip_none(lambda i: -i if i else None) + sage: x.map_support_skip_none(lambda i: -i if i else None) # optional - 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) + sage: x.map_support_skip_none(lambda i: 1 if i else None) # optional - sage.modules 5*B[1] TESTS:: - sage: y = x.map_support_skip_none(lambda i: None); y + sage: y = x.map_support_skip_none(lambda i: None); y # optional - sage.modules 0 - sage: y.parent() is B + sage: y.parent() is B # optional - 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) @@ -2092,21 +2107,21 @@ def map_item(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) - sage: x = B.an_element(); x + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules + sage: x = B.an_element(); x # optional - sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_item(lambda i, c: (-i, 2*c)) + sage: x.map_item(lambda i, c: (-i, 2*c)) # optional - 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)) + sage: x.map_item(lambda i, c: (1, 2*c)) # optional - sage.modules 14*B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = lambda m,c: (m.conjugate(), 2*c) - sage: a = s([2,1]) + s([1,1,1]) - sage: a.map_item(f) + 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 2*s[2, 1] + 2*s[3] """ return self.parent().sum_of_terms( f(m,c) for m,c in self ) @@ -2119,9 +2134,9 @@ def tensor(*elements): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example() - sage: (a,b,c) = A.algebra_generators() - sage: a.tensor(b, c) + 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 B[word: a] # B[word: b] # B[word: c] FIXME: is this a policy that we want to enforce on all parents? @@ -2151,47 +2166,50 @@ def __call_on_basis__(self, **options): EXAMPLES:: - 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: 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: phi = H(on_basis = lambda i: Y.monomial(i) + 2*Y.monomial(i+1)) # indirect doctest - sage: phi + 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 Generic morphism: From: X To: Y - sage: phi(x[1] + x[3]) + sage: phi(x[1] + x[3]) # optional - sage.modules 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") - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4], key="Y"); Y.rename("Y") - 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]) + 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 + ....: 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 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()) - sage: phi + sage: phi = H(lambda x: Y.zero()) # optional - sage.modules + sage: phi # optional - sage.modules Generic morphism: From: X To: Y - sage: phi(x[1] + x[3]) + sage: phi(x[1] + x[3]) # optional - sage.modules 0 We check that the homset category is properly set up:: - 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() + 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 Category of finite dimensional vector spaces with basis over Rational Field """ return self.domain().module_morphism(codomain=self.codomain(), @@ -2210,20 +2228,20 @@ def on_basis(self): EXAMPLES:: - 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: 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() - sage: f(2) + sage: f = H(lambda x: Y.zero()).on_basis() # optional - sage.modules + sage: f(2) # optional - sage.modules 0 - sage: f = lambda i: Y.monomial(i) + 2*Y.monomial(i+1) - sage: g = H(on_basis = f).on_basis() - sage: g(2) + 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 B[2] + 2*B[3] - sage: g == f + sage: g == f # optional - sage.modules True """ return self._on_basis @@ -2238,9 +2256,9 @@ def _on_basis(self, i): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") - sage: phi = End(X)(lambda x: 2*x) - sage: phi._on_basis(3) + 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 2*B[3] """ return self(self.domain().monomial(i)) @@ -2270,15 +2288,20 @@ def _an_element_(self): """ EXAMPLES:: - 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 - 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() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - 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 = HopfAlgebrasWithBasis(QQ).example(); B # optional - sage.combinat 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.an_element() # optional - sage.combinat sage.modules B[word: ] + 2*B[word: a] + 3*B[word: b] + B[word: bab] - sage: B.an_element() + sage: B.an_element() # optional - sage.combinat sage.modules B[()] + B[(1,2)] + 3*B[(1,2,3)] + 2*B[(1,3,2)] - sage: cartesian_product((A, B, A)).an_element() # indirect doctest + sage: ABA = cartesian_product((A, B, A)) # optional - sage.combinat sage.modules + sage: ABA.an_element() # indirect doctest # optional - sage.combinat sage.modules 2*B[(0, word: )] + 2*B[(0, word: a)] + 3*B[(0, word: b)] """ from .cartesian_product import cartesian_product @@ -2341,8 +2364,10 @@ 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"); A.rename("A") - sage: B = CombinatorialFreeModule(ZZ, [3,4], prefix="B"); B.rename("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 and `f` the bilinear morphism `(a,b) \mapsto b \otimes a` from `A \times B` to `B \otimes A`:: @@ -2353,23 +2378,23 @@ 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 + sage: a = A.monomial(1) + 2 * A.monomial(2); a # optional - sage.modules A[1] + 2*A[2] - sage: b = B.monomial(3) - 2 * B.monomial(4); b + sage: b = B.monomial(3) - 2 * B.monomial(4); b # optional - sage.modules B[3] - 2*B[4] - sage: f(a,b) + sage: f(a, b) # optional - sage.modules 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) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules 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 base ring of `A` and `B`. Here the codomain is `\ZZ`:: - sage: def f(a,b): + sage: def f(a, b): ....: return sum(a.coefficients(), 0) * sum(b.coefficients(), 0) - sage: f(a,b) + sage: f(a, b) # optional - sage.modules -3 - sage: tensor([a,b]).apply_multilinear_morphism(f) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules -3 Mind the `0` in the sums above; otherwise `f` would @@ -2377,12 +2402,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())) + sage: type(f(A.zero(), B.zero())) # optional - sage.modules <... 'int'> Which would be wrong and break this method:: - sage: tensor([a,b]).apply_multilinear_morphism(f) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules Traceback (most recent call last): ... AttributeError: 'int' object has no attribute 'parent' @@ -2390,12 +2415,14 @@ 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"); 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) + sage: C = CombinatorialFreeModule(QQ, [(1,3),(2,4)], prefix="C") # optional - sage.modules + sage: C.rename("C") # optional - sage.modules + 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 C[(1, 3)] - 4*C[(2, 4)] - sage: tensor([a,b]).apply_multilinear_morphism(f) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules C[(1, 3)] - 4*C[(2, 4)] We conclude with a real life application, where we @@ -2403,14 +2430,14 @@ def apply_multilinear_morphism(self, f, codomain=None): Symmetric functions on the Schur basis satisfies its defining formula:: - sage: Sym = SymmetricFunctions(QQ) - sage: s = Sym.schur() - sage: def f(a,b): return a*b.antipode() - sage: x = 4*s.an_element(); x + 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 8*s[] + 8*s[1] + 12*s[2] - sage: x.coproduct().apply_multilinear_morphism(f) + sage: x.coproduct().apply_multilinear_morphism(f) # optional - sage.combinat sage.modules 8*s[] - sage: x.coproduct().apply_multilinear_morphism(f) == x.counit() + sage: x.coproduct().apply_multilinear_morphism(f) == x.counit() # optional - sage.combinat sage.modules True We recover the constant term of `x`, as desired. @@ -2445,6 +2472,7 @@ def extra_super_categories(self): sage: ModulesWithBasis(ZZ).DualObjects().extra_super_categories() [Category of modules over Integer Ring] sage: ModulesWithBasis(QQ).DualObjects().super_categories() - [Category of duals of vector spaces over Rational Field, Category of duals of modules with basis over Rational Field] + [Category of duals of vector spaces over Rational Field, + Category of duals of modules with basis over Rational Field] """ return [Modules(self.base_category().base_ring())] diff --git a/src/sage/categories/monoids.py b/src/sage/categories/monoids.py index dc548a72e66..386b1b133f1 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() + sage: R.submonoid([R.one()]).list() # optional - sage.groups [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) + sage: Monoids.free(index_set=ZZ) # optional - sage.groups Free monoid indexed by Integer Ring - sage: Monoids().free(ZZ) + sage: Monoids().free(ZZ) # optional - sage.groups Free monoid indexed by Integer Ring - sage: F. = Monoids().free(); F + sage: F. = Monoids().free(); F # optional - sage.groups 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]) - sage: M.semigroup_generators() + sage: M = Monoids().free([1,2,3]) # optional - sage.groups + sage: M.semigroup_generators() # optional - sage.groups 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 + sage: M = R.submonoid([R(3), R(5)]); M # optional - sage.groups A submonoid of (Ring of integers modulo 15) with 2 generators - sage: M.list() + sage: M.list() # optional - sage.groups [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 + sage: S = R.subsemigroup([R(3), R(5)]); S # optional - sage.groups A subsemigroup of (Ring of integers modulo 15) with 2 generators - sage: S.list() + sage: S.list() # optional - sage.groups [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()) - sage: M2 is M + sage: M2 = R.subsemigroup([R(3), R(5)], one=R.one()) # optional - sage.groups + sage: M2 is M # optional - sage.groups True """ return self.subsemigroup(generators, one=self.one()) @@ -245,11 +245,11 @@ def _div_(left, right): EXAMPLES:: - 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) + 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 (x0*x1^-1, x1*x0^-1) With this default implementation, division will fail as @@ -267,7 +267,7 @@ def _div_(left, right): TESTS:: - sage: c1._div_.__module__ + sage: c1._div_.__module__ # optional - sage.groups 'sage.categories.monoids' """ return left * ~right @@ -336,8 +336,8 @@ def powers(self, n): EXAMPLES:: - sage: A = Matrix([[1, 1], [-1, 0]]) - sage: A.powers(6) + sage: A = Matrix([[1, 1], [-1, 0]]) # optional - sage.modules + sage: A.powers(6) # optional - 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 +363,8 @@ def __invert__(self): EXAMPLES:: - sage: A = Matrix([[1, 0], [1, 1]]) - sage: ~A + sage: A = Matrix([[1, 0], [1, 1]]) # optional - sage.modules + sage: ~A # optional - sage.modules [ 1 0] [-1 1] """ @@ -379,7 +379,7 @@ def inverse(self): EXAMPLES:: - sage: AA(sqrt(~2)).inverse() + sage: AA(sqrt(~2)).inverse() # optional - sage.symbolic sage.rings.number_field 1.414213562373095? """ # Nota Bene: Element classes should implement ``__invert__`` only. @@ -412,11 +412,11 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Monoids.Commutative.free(index_set=ZZ) + sage: Monoids.Commutative.free(index_set=ZZ) # optional - sage.groups Free abelian monoid indexed by Integer Ring - sage: Monoids().Commutative().free(ZZ) + sage: Monoids().Commutative().free(ZZ) # optional - sage.groups Free abelian monoid indexed by Integer Ring - sage: F. = Monoids().Commutative().free(); F + sage: F. = Monoids().Commutative().free(); F # optional - sage.groups Free abelian monoid indexed by {'x', 'y', 'z'} """ if names is not None: @@ -447,18 +447,18 @@ def one(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.one.__module__ + sage: A.one.__module__ # optional - sage.combinat sage.modules 'sage.categories.monoids' - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules F[{}] TESTS:: - sage: A.one() is A.a_realization().one() + sage: A.one() is A.a_realization().one() # optional - sage.combinat sage.modules True - sage: A._test_one() + sage: A._test_one() # optional - sage.combinat sage.modules """ return self.a_realization().one() @@ -510,12 +510,12 @@ def one_basis(self): EXAMPLES:: - sage: A = Monoids().example().algebra(ZZ) - sage: A.one_basis() + sage: A = Monoids().example().algebra(ZZ) # optional - sage.modules + sage: A.one_basis() # optional - sage.modules '' - sage: A.one() + sage: A.one() # optional - sage.modules B[''] - sage: A(3) + sage: A(3) # optional - sage.modules 3*B[''] """ return self.basis().keys().one() @@ -542,7 +542,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() + sage: M.algebra(ZZ).algebra_generators() # optional - sage.modules Finite family {'a': B['a'], 'b': B['b'], 'c': B['c'], 'd': B['d']} sage: Z12 = Monoids().Finite().example(); Z12 @@ -555,17 +555,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() + sage: Z12.algebra(QQ).algebra_generators() # optional - 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: GroupAlgebras(QQ).example(AlternatingGroup(10)).algebra_generators() + sage: A10 = AlternatingGroup(10) # optional - sage.groups + sage: GroupAlgebras(QQ).example(A10).algebra_generators() # optional - sage.groups sage.modules Family ((8,9,10), (1,2,3,4,5,6,7,8,9)) - sage: A = DihedralGroup(3).algebra(QQ); A + sage: A = DihedralGroup(3).algebra(QQ); A # optional - sage.groups sage.modules Algebra of Dihedral group of order 6 as a permutation group over Rational Field - sage: A.algebra_generators() + sage: A.algebra_generators() # optional - sage.groups sage.modules Family ((1,2,3), (1,3)) """ monoid = self.basis().keys() @@ -583,14 +584,15 @@ def is_central(self): EXAMPLES:: - sage: SG4 = SymmetricGroupAlgebra(ZZ,4) - sage: SG4(1).is_central() + sage: SG4 = SymmetricGroupAlgebra(ZZ,4) # optional - sage.groups sage.modules + sage: SG4(1).is_central() # optional - sage.groups sage.modules True - sage: SG4(Permutation([1,3,2,4])).is_central() + sage: SG4(Permutation([1,3,2,4])).is_central() # optional - sage.groups sage.modules False - sage: A = GroupAlgebras(QQ).example(); A - Algebra of Dihedral group of order 8 as a permutation group over Rational Field - sage: sum(i for i in A.basis()).is_central() + sage: A = GroupAlgebras(QQ).example(); A # optional - sage.groups sage.modules + Algebra of Dihedral group of order 8 + as a permutation group over Rational Field + sage: sum(i for i in A.basis()).is_central() # optional - sage.groups sage.modules True """ return all(i * self == self * i @@ -628,19 +630,19 @@ def monoid_generators(self): EXAMPLES:: - sage: M = Monoids.free([1,2,3]) - sage: N = Monoids.free(['a','b']) - sage: C = cartesian_product([M, N]) - sage: C.monoid_generators() + 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 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) - sage: C = cartesian_product([M, N]) - sage: C.monoid_generators() + sage: N = Monoids.free(ZZ) # optional - sage.groups + sage: C = cartesian_product([M, N]) # optional - sage.groups + sage: C.monoid_generators() # optional - sage.groups Lazy family (gen(i))_{i in The Cartesian product of (...)} """ F = self.cartesian_factors() @@ -677,10 +679,10 @@ def multiplicative_order(self): EXAMPLES:: - 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() + 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 12 """ from sage.rings.infinity import Infinity @@ -697,10 +699,10 @@ def __invert__(self): EXAMPLES:: - sage: a1 = Permutation((4,2,1,3)) - sage: a2 = SL(2,3)([2,1,1,1]) - sage: h = cartesian_product([a1,a2]) - sage: ~h + 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 ([2, 4, 1, 3], [1 2] [2 2]) """ diff --git a/src/sage/categories/morphism.pyx b/src/sage/categories/morphism.pyx index 031b41218e3..514140b2333 100644 --- a/src/sage/categories/morphism.pyx +++ b/src/sage/categories/morphism.pyx @@ -69,25 +69,25 @@ cdef class Morphism(Map): EXAMPLES:: sage: R. = ZZ[] - sage: f = R.hom([t+1]) + sage: f = R.hom([t + 1]) sage: f # indirect doctest Ring endomorphism of Univariate Polynomial Ring in t over Integer Ring Defn: t |--> t + 1 TESTS:: - sage: K = CyclotomicField(12) - sage: L = CyclotomicField(132) - sage: phi = L._internal_coerce_map_from(K); phi + 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 (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 + sage: del K # optional - sage.rings.number_field sage: import gc sage: _ = gc.collect() - sage: phi + sage: phi # optional - sage.rings.number_field Defunct morphism """ D = self.domain() @@ -182,10 +182,10 @@ cdef class Morphism(Map): and left modules over (euclidean domains and infinite enumerated sets and metric spaces) - sage: K = CyclotomicField(12) - sage: L = CyclotomicField(132) - sage: phi = L._internal_coerce_map_from(K) - sage: phi.category() + 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 Category of homsets of number fields """ # Should it be Category of elements of ...? @@ -202,10 +202,10 @@ cdef class Morphism(Map): sage: f.is_endomorphism() True - sage: K = CyclotomicField(12) - sage: L = CyclotomicField(132) - sage: phi = L._internal_coerce_map_from(K) - sage: phi.is_endomorphism() + 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 False """ return self.parent().is_endomorphism_set() @@ -260,7 +260,9 @@ cdef class Morphism(Map): sage: x^2 + y Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Integer Ring' + TypeError: unsupported operand parent(s) for +: + 'Univariate Polynomial Ring in x over Integer Ring' and + 'Univariate Polynomial Ring in y over Integer Ring' Let us declare a coercion from `\ZZ[x]` to `\ZZ[z]`:: @@ -284,7 +286,9 @@ cdef class Morphism(Map): sage: phi.register_as_coercion() Traceback (most recent call last): ... - AssertionError: coercion from Univariate Polynomial Ring in x over Integer Ring to Univariate Polynomial Ring in z over Integer Ring already registered or discovered + AssertionError: coercion from Univariate Polynomial Ring in x over Integer Ring + to Univariate Polynomial Ring in z over Integer Ring + already registered or discovered """ self._codomain.register_coercion(self) @@ -300,14 +304,14 @@ cdef class Morphism(Map): Let us declare a conversion from the symmetric group to `\ZZ` through the sign map:: - sage: S = SymmetricGroup(4) - sage: phi = Hom(S, ZZ)(lambda x: ZZ(x.sign())) - sage: x = S.an_element(); x + 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 (2,3,4) - sage: phi(x) + sage: phi(x) # optional - sage.groups 1 - sage: phi.register_as_conversion() - sage: ZZ(x) + sage: phi.register_as_conversion() # optional - sage.groups + sage: ZZ(x) # optional - sage.groups 1 """ self._codomain.register_conversion(self) @@ -347,26 +351,27 @@ cdef class Morphism(Map): TESTS:: sage: from sage.categories.morphism import SetMorphism - sage: E = End(Partitions(5)) - sage: f = E.identity() - sage: g = SetMorphism(E, lambda x:x) - sage: f == g + 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 Traceback (most recent call last): ... - NotImplementedError: unable to compare morphisms of type <... 'sage.categories.morphism.IdentityMorphism'> and <... 'sage.categories.morphism.SetMorphism'> with domain Partitions of the integer 5 + NotImplementedError: unable to compare morphisms of type <... 'sage.categories.morphism.IdentityMorphism'> + and <... 'sage.categories.morphism.SetMorphism'> with domain Partitions of the integer 5 We check that :trac:`28617` is fixed:: - sage: FF = GF(2^20) - sage: f = FF.frobenius_endomorphism() - sage: f == FF.frobenius_endomorphism() + 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 True and that :trac:`29632` is fixed:: - sage: R. = QuadraticField(-1)[] - sage: f = R.hom(R.gens(), R) - sage: f.is_identity() + 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 True """ if self is other: @@ -502,17 +507,17 @@ cdef class IdentityMorphism(Morphism): EXAMPLES:: - sage: E = End(Partitions(5)) - sage: E.identity().is_identity() + sage: E = End(Partitions(5)) # optional - sage.combinat + sage: E.identity().is_identity() # optional - sage.combinat True Check that :trac:`15478` is fixed:: - sage: K. = GF(4) - sage: phi = End(K)([z^2]) - sage: R. = K[] - sage: psi = End(R)(phi) - sage: psi.is_identity() + 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 False """ return True diff --git a/src/sage/categories/number_fields.py b/src/sage/categories/number_fields.py index 8386ea03912..f3610cd8b7f 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 + sage: K = NumberField(x - 1, 'a'); K # optional - sage.rings.number_field Number Field in a with defining polynomial x - 1 - sage: K in C + sage: K in C # optional - 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') - sage: K in C + sage: K = NumberField(x^2 + 1, 'a') # optional - sage.rings.number_field + sage: K in C # optional - 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() + sage: NumberField(x^2 + 1, 'a') in NumberFields() # optional - sage.rings.number_field True - sage: QuadraticField(-97, 'theta') in NumberFields() + sage: QuadraticField(-97, 'theta') in NumberFields() # optional - sage.rings.number_field True - sage: CyclotomicField(97) in NumberFields() + sage: CyclotomicField(97) in NumberFields() # optional - 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')) + sage: C(NumberField(x^2 + 1, 'a')) # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 + 1 - sage: C(UnitGroup(NumberField(x^2 + 1, 'a'))) # indirect doctest + sage: C(UnitGroup(NumberField(x^2 + 1, 'a'))) # indirect doctest # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 + 1 sage: C(ZZ) @@ -151,34 +151,35 @@ def zeta_function(self, prec=53, EXAMPLES:: - sage: K. = NumberField(ZZ['x'].0^2+ZZ['x'].0-1) - sage: Z = K.zeta_function(); Z # optional - sage.symbolic - PARI zeta function associated to Number Field in a with defining polynomial x^2 + x - 1 - sage: Z(-1) # optional - sage.symbolic + 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 + 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 0.0333333333333333 - sage: x = polygen(QQ, 'x') # optional - sage.symbolic - sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.symbolic - sage: Z = L.zeta_function() # optional - sage.symbolic - sage: Z(5) # optional - sage.symbolic + 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 1.00199015670185 Using the algorithm "pari":: - sage: K. = NumberField(ZZ['x'].0^2+ZZ['x'].0-1) # optional - sage.symbolic - sage: Z = K.zeta_function(algorithm="pari") # optional - sage.symbolic - sage: Z(-1) # optional - sage.symbolic + 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 0.0333333333333333 - sage: x = polygen(QQ, 'x') # optional - sage.symbolic - sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.symbolic - sage: Z = L.zeta_function(algorithm="pari") # optional - sage.symbolic - sage: Z(5) # optional - sage.symbolic + 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 1.00199015670185 TESTS:: - sage: QQ.zeta_function() # optional - sage.symbolic + sage: QQ.zeta_function() # optional - sage.symbolic PARI zeta function associated to Rational Field """ if algorithm == 'gp': @@ -222,8 +223,9 @@ def _test_absolute_disc(self, **options): EXAMPLES:: - sage: S = NumberField(x**3-x-1, 'a') - sage: S._test_absolute_disc() + 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 """ 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 20e43bff108..7bfb89bd2ae 100644 --- a/src/sage/categories/polyhedra.py +++ b/src/sage/categories/polyhedra.py @@ -26,10 +26,10 @@ class PolyhedralSets(Category_over_base_ring): sage: TestSuite(PolyhedralSets(RDF)).run() - sage: P = Polyhedron() - sage: P.parent().category().element_class + sage: P = Polyhedron() # optional - sage.geometry.polyhedron + sage: P.parent().category().element_class # optional - sage.geometry.polyhedron - sage: P.parent().category().element_class.mro() + sage: P.parent().category().element_class.mro() # optional - sage.geometry.polyhedron [, , , @@ -45,7 +45,7 @@ class PolyhedralSets(Category_over_base_ring): , , ] - sage: isinstance(P, P.parent().category().element_class) + sage: isinstance(P, P.parent().category().element_class) # optional - sage.geometry.polyhedron True """ @@ -53,7 +53,7 @@ def __init__(self, R): """ TESTS:: - sage: PolyhedralSets(AA) + sage: PolyhedralSets(AA) # optional - 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 d0fca4b658d..6912c4878cf 100644 --- a/src/sage/categories/poor_man_map.py +++ b/src/sage/categories/poor_man_map.py @@ -39,7 +39,7 @@ class PoorManMap(sage.structure.sage_object.SageObject): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1, 2, 3), codomain = (1, 2, 6)) + sage: f = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6)) sage: f A map from (1, 2, 3) to (1, 2, 6) sage: f(3) @@ -48,12 +48,12 @@ class PoorManMap(sage.structure.sage_object.SageObject): The composition of several functions can be created by passing in a tuple of functions:: - sage: i = PoorManMap((factorial, sqrt), domain= (1, 4, 9), codomain = (1, 2, 6)) + sage: i = PoorManMap((factorial, sqrt), domain=(1, 4, 9), codomain=(1, 2, 6)) However, the same effect can also be achieved by just composing maps:: - sage: g = PoorManMap(factorial, domain = (1, 2, 3), codomain = (1, 2, 6)) - sage: h = PoorManMap(sqrt, domain = (1, 4, 9), codomain = (1, 2, 3)) + sage: g = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6)) + sage: h = PoorManMap(sqrt, domain=(1, 4, 9), codomain=(1, 2, 3)) sage: i == g*h True @@ -63,8 +63,8 @@ def __init__(self, function, domain=None, codomain=None, name=None): TESTS:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1, 2, 3), codomain = (1, 2, 6)) - sage: g = PoorManMap(sqrt, domain = (1, 4, 9), codomain = (1, 2, 6)) + sage: f = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6)) + sage: g = PoorManMap(sqrt, domain=(1, 4, 9), codomain=(1, 2, 6)) sage: TestSuite(f).run() sage: TestSuite(f*g).run() @@ -85,11 +85,11 @@ def _repr_(self): sage: from sage.categories.poor_man_map import PoorManMap sage: PoorManMap(lambda x: x+2) # indirect doctest A map - sage: PoorManMap(lambda x: x+2, domain = (1,2,3)) + sage: PoorManMap(lambda x: x+2, domain=(1,2,3)) A map from (1, 2, 3) - sage: PoorManMap(lambda x: x+2, domain = (1,2,3)) + sage: PoorManMap(lambda x: x+2, domain=(1,2,3)) A map from (1, 2, 3) - sage: PoorManMap(lambda x: x+2, codomain = (3,4,5)) + sage: PoorManMap(lambda x: x+2, codomain=(3,4,5)) A map to (3, 4, 5) """ @@ -104,7 +104,7 @@ def domain(self): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)).domain() + sage: PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)).domain() (1, 2, 3) """ return self._domain @@ -116,7 +116,7 @@ def codomain(self): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)).codomain() + sage: PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)).codomain() (2, 3, 4) """ return self._codomain @@ -128,12 +128,12 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: g = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: h1 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h2 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h3 = PoorManMap(factorial, domain = (1,2,3,4), codomain = (1,2,6)) - sage: h4 = PoorManMap(lambda x: x, domain = (1,2,3), codomain = (1,2,6)) + sage: f = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: g = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: h1 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h2 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h3 = PoorManMap(factorial, domain=(1,2,3,4), codomain=(1,2,6)) + sage: h4 = PoorManMap(lambda x: x, domain=(1,2,3), codomain=(1,2,6)) sage: f == g, f == h1, f == h2, f == h3, f == h4, f == 1, 1 == f (True, False, False, False, False, False, False) @@ -153,12 +153,12 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: g = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: h1 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h2 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h3 = PoorManMap(factorial, domain = (1,2,3,4), codomain = (1,2,6)) - sage: h4 = PoorManMap(lambda x: x, domain = (1,2,3), codomain = (1,2,6)) + sage: f = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: g = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: h1 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h2 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h3 = PoorManMap(factorial, domain=(1,2,3,4), codomain=(1,2,6)) + sage: h4 = PoorManMap(lambda x: x, domain=(1,2,3), codomain=(1,2,6)) sage: f != g, f != h1, f != h2, f != h3, f != h4, f != 1, 1 != f (False, True, True, True, True, True, True) @@ -172,8 +172,8 @@ def __hash__(self): TESTS:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: g = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) + sage: f = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: g = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) sage: hash(f) == hash(g) True @@ -194,8 +194,8 @@ def __mul__(self, other): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)) - sage: g = PoorManMap(lambda x: -x, domain = (2,3,4), codomain = (-2,-3,-4)) + sage: f = PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)) + sage: g = PoorManMap(lambda x: -x, domain=(2,3,4), codomain=(-2,-3,-4)) sage: g*f A map from (1, 2, 3) to (-2, -3, -4) @@ -208,8 +208,8 @@ 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 = PoorManMap(factorial, domain=ZZ, codomain=ZZ) + sage: h = PoorManMap(sqrt, domain=RR, codomain=CC) sage: g*h Traceback (most recent call last): ... @@ -248,11 +248,11 @@ def __call__(self, *args): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)) + sage: f = PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)) sage: f(2) 3 - sage: g = PoorManMap(lambda x: -x, domain = (2,3,4), codomain = (-2,-3,-4)) + sage: g = PoorManMap(lambda x: -x, domain=(2,3,4), codomain=(-2,-3,-4)) sage: (g*f)(2) -3 @@ -266,8 +266,8 @@ def _sympy_(self): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: h = PoorManMap(sin, domain=RR, codomain=RR) - sage: h._sympy_() + sage: h = PoorManMap(sin, domain=RR, codomain=RR) # optional - sage.symbolic + sage: h._sympy_() # optional - sage.symbolic sin """ from sympy import Lambda, sympify diff --git a/src/sage/categories/posets.py b/src/sage/categories/posets.py index b1a2ba1942d..24a83e02dbd 100644 --- a/src/sage/categories/posets.py +++ b/src/sage/categories/posets.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs, sage.combinat r""" Posets """ @@ -112,7 +113,8 @@ def example(self, choice=None): An example of a poset: sets ordered by inclusion sage: Posets().example("facade") - An example of a facade poset: the positive integers ordered by divisibility + An example of a facade poset: + the positive integers ordered by divisibility """ from sage.categories.examples.posets import FiniteSetsOrderedByInclusion, PositiveIntegersOrderedByDivisibilityFacade if choice == "facade": @@ -457,7 +459,8 @@ def is_order_ideal(self, o): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_order_ideal([1, 3]) @@ -483,7 +486,8 @@ def is_order_filter(self, o): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_order_filter([4, 12]) @@ -527,7 +531,8 @@ def is_chain_of_poset(self, o, ordered=False): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_chain_of_poset([1, 3]) @@ -575,11 +580,16 @@ def is_chain_of_poset(self, o, ordered=False): sage: from sage.categories.examples.posets import FiniteSetsOrderedByInclusion sage: R = FiniteSetsOrderedByInclusion() - sage: R.is_chain_of_poset([R(set([3, 1, 2])), R(set([1, 4])), R(set([4, 5]))]) + sage: R.is_chain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 4])), + ....: R(set([4, 5]))]) False - sage: R.is_chain_of_poset([R(set([3, 1, 2])), R(set([1, 2])), R(set([1]))], ordered=True) + sage: R.is_chain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 2])), + ....: R(set([1]))], ordered=True) False - sage: R.is_chain_of_poset([R(set([3, 1, 2])), R(set([1, 2])), R(set([1]))]) + sage: R.is_chain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 2])), R(set([1]))]) True sage: from sage.categories.examples.posets import PositiveIntegersOrderedByDivisibilityFacade @@ -632,7 +642,8 @@ def is_antichain_of_poset(self, o): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_antichain_of_poset([1, 3]) @@ -653,9 +664,11 @@ def is_antichain_of_poset(self, o): False sage: P.is_antichain_of_poset([6, 4]) True - sage: P.is_antichain_of_poset(i for i in divisors(12) if (2 < i and i < 6)) + sage: P.is_antichain_of_poset(i for i in divisors(12) + ....: if (2 < i and i < 6)) True - sage: P.is_antichain_of_poset(i for i in divisors(12) if (2 <= i and i < 6)) + sage: P.is_antichain_of_poset(i for i in divisors(12) + ....: if (2 <= i and i < 6)) False sage: Q = Poset({2: [3, 1], 3: [4], 1: [4]}) @@ -680,9 +693,11 @@ def is_antichain_of_poset(self, o): sage: from sage.categories.examples.posets import FiniteSetsOrderedByInclusion sage: R = FiniteSetsOrderedByInclusion() - sage: R.is_antichain_of_poset([R(set([3, 1, 2])), R(set([1, 4])), R(set([4, 5]))]) + sage: R.is_antichain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 4])), R(set([4, 5]))]) True - sage: R.is_antichain_of_poset([R(set([3, 1, 2, 4])), R(set([1, 4])), R(set([4, 5]))]) + sage: R.is_antichain_of_poset([R(set([3, 1, 2, 4])), + ....: R(set([1, 4])), R(set([4, 5]))]) False """ return all(not self.lt(x,y) for x in o for y in o) diff --git a/src/sage/categories/primer.py b/src/sage/categories/primer.py index 7ecc75e711a..84ab37f34b7 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() + sage: Permutations(5).cardinality() # optional - sage.combinat 120 - sage: GL(2,2).cardinality() + sage: GL(2,2).cardinality() # optional - sage.groups 6 - sage: A = random_matrix(ZZ,6,3,x=7) - sage: L = LatticePolytope(A.rows()) - sage: L.npoints() # oops! # random + sage: A = random_matrix(ZZ, 6, 3, x=7) # optional - sage.modules + sage: L = LatticePolytope(A.rows()) # optional - sage.geometry.polyhedron + sage: L.npoints() # oops! # random # optional - sage.geometry.polyhedron 37 - How to ensure robustness? @@ -98,8 +98,9 @@ :: - 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 + sage: m = random_matrix(QQ, 4, algorithm='echelonizable', # optional - sage.modules + ....: rank=3, upper_bound=60) + sage: m^8 == m*m*m*m*m*m*m*m == ((m^2)^2)^2 # optional - sage.modules True We want to implement binary powering only once, as *generic* code @@ -130,7 +131,7 @@ That's our bookshelf! And it's used in many places:: - sage: GL(2,ZZ) in Monoids() + sage: GL(2, ZZ) in Monoids() # optional - sage.modules True sage: NN in Monoids() True @@ -168,20 +169,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) - sage: G.category() + sage: G = GL(2, ZZ) # optional - sage.modules + sage: G.category() # optional - 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() + sage: G in Semigroups() # optional - sage.modules True Altogether, our group gets algorithms from a bunch of bookshelves:: - sage: G.categories() + sage: G.categories() # optional - sage.modules [Category of infinite groups, Category of groups, Category of monoids, ..., Category of magmas, @@ -189,19 +190,19 @@ Those can be viewed graphically:: - sage: g = Groups().category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + 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 In case ``dot2tex`` is not available, you can use instead:: - sage: g.show(vertex_shape=None, figsize=20) + sage: g.show(vertex_shape=None, figsize=20) # optional - sage.modules sage.graphs sage.plot Here is an overview of all categories in Sage:: - sage: g = sage.categories.category.category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + 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 Wrap-up: generic algorithms in Sage are organized in a hierarchy of bookshelves modelled upon the usual hierarchy of categories provided @@ -370,9 +371,9 @@ Category of sets with partial maps, Category of objects] - sage: g = EuclideanDomains().category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + 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 A bit of help from computer science =================================== @@ -406,11 +407,11 @@ 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: x = var('x') # optional - sage.symbolic + sage: p = 6*x^2 + 12*x + 6 # optional - sage.symbolic + sage: type(p) # optional - sage.symbolic - sage: p.factor() # optional - sage.symbolic + sage: p.factor() # optional - sage.symbolic 6*(x + 1)^2 sage: R. = PolynomialRing(QQ, sparse=True) @@ -466,9 +467,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) - sage: m = P.an_element() - sage: for cls in m.__class__.mro(): print(cls) + 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 @@ -486,9 +487,9 @@ class implements: The full hierarchy is best viewed graphically:: - sage: g = class_graph(m.__class__) - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + 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 Parallel hierarchy of classes for parents ----------------------------------------- @@ -522,13 +523,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) - sage: type(G) + sage: G = GL(2, ZZ) # optional - sage.modules + sage: type(G) # optional - sage.modules Here is a piece of the hierarchy of classes above it:: - sage: for cls in G.__class__.mro(): print(cls) + sage: for cls in G.__class__.mro(): print(cls) # optional - sage.modules ... @@ -540,10 +541,10 @@ class implements: categories and parallel to that we had seen for the elements. This is best viewed graphically:: - 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 + 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 .. NOTE:: @@ -724,7 +725,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() + sage: Groups().example() # optional - sage.modules General Linear Group of degree 4 over Rational Field which gives an example of object of the category. Besides illustrating @@ -1017,16 +1018,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 + sage: P = PermutationGroup([[(1,2,3)]]); P # optional - sage.combinat Permutation Group with generators [(1,2,3)] - sage: P.category() + sage: P.category() # optional - 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)]], category=PermutationGroups().Finite().Commutative()); P + sage: P = PermutationGroup([[(1,2,3)]], # optional - sage.combinat + ....: category=PermutationGroups().Finite().Commutative()); P Permutation Group with generators [(1,2,3)] - sage: P.category() + sage: P.category() # optional - sage.combinat Category of finite enumerated commutative permutation groups This feature can even be used, typically in experimental code, to add @@ -1041,18 +1043,18 @@ class SubcategoryMethods: ....: class ElementMethods: ....: def bar(self): print("bar") - sage: P = PermutationGroup([[(1,2,3)]], category=Foos()) - sage: P.foo() + sage: P = PermutationGroup([[(1,2,3)]], category=Foos()) # optional - sage.combinat + sage: P.foo() # optional - sage.combinat foo - sage: p = P.an_element() - sage: p.bar() + sage: p = P.an_element() # optional - sage.combinat + sage: p.bar() # optional - sage.combinat 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 + sage: P = PermutationGroup([[(1,2,3)]], category=Sets()) # todo: not implemented # optional - 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 @@ -1100,9 +1102,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") - sage: B = HopfAlgebrasWithBasis(QQ).example(); B.rename("B") - sage: C = cartesian_product([A, B, B]); C + 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 A (+) B (+) B In which category should this new parent be? Since `A` and `B` are @@ -1111,14 +1113,14 @@ class SubcategoryMethods: are monoids, `A \times B \times B` is naturally endowed with a monoid structure for pointwise multiplication:: - sage: C in Monoids() + sage: C in Monoids() # optional - sage.combinat sage.modules True the unit being the Cartesian product of the units of the operands:: - sage: C.one() + sage: C.one() # optional - sage.combinat sage.modules B[(0, word: )] + B[(1, ())] + B[(2, ())] - sage: cartesian_product([A.one(), B.one(), B.one()]) + sage: cartesian_product([A.one(), B.one(), B.one()]) # optional - sage.combinat sage.modules B[(0, word: )] + B[(1, ())] + B[(2, ())] The pointwise product can be implemented generically for all magmas @@ -1126,7 +1128,7 @@ class SubcategoryMethods: constructed as Cartesian products. It's thus implemented in the :class:`Magmas` category:: - sage: C.product.__module__ + sage: C.product.__module__ # optional - sage.combinat sage.modules 'sage.categories.magmas' More specifically, keeping on using nested classes to structure the @@ -1158,7 +1160,7 @@ class naming and introspection. Sage currently works around the Let us now look at the categories of ``C``:: - sage: C.categories() + sage: C.categories() # optional - 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, ... @@ -1369,13 +1371,14 @@ class naming and introspection. Sage currently works around the sage: C = (Magmas() & AdditiveMagmas()).Distributive(); C Category of distributive magmas and additive magmas - sage: C.Associative().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().AdditiveInverse() + sage: CAA = C.Associative().AdditiveAssociative() + sage: CAA.AdditiveCommutative().AdditiveUnital().AdditiveInverse() Category of rngs - sage: C.Associative().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().Unital() + sage: CAA.AdditiveCommutative().AdditiveUnital().Unital() Category of semirings - sage: C.Associative().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().AdditiveInverse().Unital() + sage: CAA.AdditiveCommutative().AdditiveUnital().AdditiveInverse().Unital() Category of rings sage: Rings().Division() @@ -1389,9 +1392,9 @@ class naming and introspection. Sage currently works around the or for more advanced categories:: - sage: g = HopfAlgebras(QQ).WithBasis().Graded().Connected().category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + 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 Difference between axioms and regressive covariant functorial constructions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1413,7 +1416,7 @@ class naming and introspection. Sage currently works around the A finite dimensional algebra is also a finite dimensional module:: - sage: Algebras(QQ).FiniteDimensional().is_subcategory( Modules(QQ).FiniteDimensional() ) + sage: Algebras(QQ).FiniteDimensional().is_subcategory(Modules(QQ).FiniteDimensional()) True Similarly a graded algebra is also a graded module:: diff --git a/src/sage/categories/principal_ideal_domains.py b/src/sage/categories/principal_ideal_domains.py index 2821fdf0ef6..fa8b2632cc1 100644 --- a/src/sage/categories/principal_ideal_domains.py +++ b/src/sage/categories/principal_ideal_domains.py @@ -70,22 +70,22 @@ 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() + sage: QQbar['x']._test_gcd_vs_xgcd() # optional - 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) - sage: O = K.maximal_order() - sage: O in UniqueFactorizationDomains() + 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 False - sage: R = PolynomialRing(O, 'x') - sage: F = R.fraction_field() - sage: F in PrincipalIdealDomains() + 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 True - sage: F._test_gcd_vs_xgcd() + sage: F._test_gcd_vs_xgcd() # optional - sage.rings.number_field """ tester = self._tester(**options) elts = list(tester.some_elements()) diff --git a/src/sage/categories/pushout.py b/src/sage/categories/pushout.py index 71c20a6d82b..69b936bb3ff 100644 --- a/src/sage/categories/pushout.py +++ b/src/sage/categories/pushout.py @@ -107,17 +107,20 @@ class ConstructionFunctor(Functor): sage: P. = ZZ[] sage: F = P.construction()[0]; F MPoly[x,y] - 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) - Ring endomorphism of Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 + 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 + 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 + 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 + 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) + sage: F(f)(F(A)(x)*a) # optional - sage.rings.finite_rings (a + b)*x """ @@ -430,22 +433,27 @@ class CompositeConstructionFunctor(ConstructionFunctor): EXAMPLES:: sage: from sage.categories.pushout import CompositeConstructionFunctor - sage: F = CompositeConstructionFunctor(QQ.construction()[0],ZZ['x'].construction()[0],QQ.construction()[0],ZZ['y'].construction()[0]) + sage: F = CompositeConstructionFunctor(QQ.construction()[0], ZZ['x'].construction()[0], + ....: QQ.construction()[0], ZZ['y'].construction()[0]) sage: F Poly[y](FractionField(Poly[x](FractionField(...)))) sage: F == loads(dumps(F)) True sage: F == CompositeConstructionFunctor(*F.all) True - sage: F(GF(2)['t']) - Univariate Polynomial Ring in y over Fraction Field of Univariate Polynomial Ring in x over Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) + sage: F(GF(2)['t']) # optional - sage.rings.finite_rings + Univariate Polynomial Ring in y + over Fraction Field of Univariate Polynomial Ring in x + over Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) """ def __init__(self, *args): """ TESTS:: sage: from sage.categories.pushout import CompositeConstructionFunctor - sage: F = CompositeConstructionFunctor(QQ.construction()[0],ZZ['x'].construction()[0],QQ.construction()[0],ZZ['y'].construction()[0]) + sage: F = CompositeConstructionFunctor(QQ.construction()[0], ZZ['x'].construction()[0], + ....: QQ.construction()[0], ZZ['y'].construction()[0]) sage: F Poly[y](FractionField(Poly[x](FractionField(...)))) sage: F == CompositeConstructionFunctor(*F.all) @@ -587,7 +595,10 @@ def expand(self): EXAMPLES:: sage: from sage.categories.pushout import CompositeConstructionFunctor - sage: F = CompositeConstructionFunctor(QQ.construction()[0],ZZ['x'].construction()[0],QQ.construction()[0],ZZ['y'].construction()[0]) + sage: F = CompositeConstructionFunctor(QQ.construction()[0], + ....: ZZ['x'].construction()[0], + ....: QQ.construction()[0], + ....: ZZ['y'].construction()[0]) sage: F Poly[y](FractionField(Poly[x](FractionField(...)))) sage: prod(F.expand()) == F @@ -801,32 +812,32 @@ class PolynomialFunctor(ConstructionFunctor): EXAMPLES:: sage: P = ZZ['t'].construction()[0] - sage: P(GF(3)) + sage: P(GF(3)) # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 3 - sage: P == loads(dumps(P)) + sage: P == loads(dumps(P)) # optional - sage.rings.finite_rings True - sage: R. = GF(5)[] - sage: f = R.hom([x+2*y,3*x-y],R) - sage: P(f)((x+y)*P(R).0) + 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 (-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) - sage: F,B = R.construction() - sage: F(B) is R + 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 True sage: S. = PolynomialRing(ZZ) - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.rings.finite_rings False - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.rings.finite_rings False - sage: S.0 + R.0 + sage: S.0 + R.0 # optional - sage.rings.finite_rings 2*x - sage: (S.0 + R.0).parent() + sage: (S.0 + R.0).parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 - sage: (S.0 + R.0).parent().is_sparse() + sage: (S.0 + R.0).parent().is_sparse() # optional - sage.rings.finite_rings False """ @@ -838,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)) + sage: P(GF(3)) # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 3 There is an optional parameter ``multi_variate``, but @@ -865,7 +876,7 @@ def _apply_functor(self, R): TESTS:: sage: P = ZZ['x'].construction()[0] - sage: P(GF(3)) # indirect doctest + sage: P(GF(3)) # indirect doctest # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 3 """ @@ -882,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 + sage: P(ZZ.hom(GF(3))) # indirect doctest # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Univariate Polynomial Ring in x over Finite Field of size 3 @@ -992,17 +1003,19 @@ class MultiPolynomialFunctor(ConstructionFunctor): sage: P. = ZZ[] sage: F = P.construction()[0]; F MPoly[x,y] - 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) - 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 + sage: A. = GF(5)[] # optional - sage.rings.finite_rings + sage: F(A) # optional - sage.rings.finite_rings + 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 + 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) + sage: F(f)(F(A)(x)*a) # optional - sage.rings.finite_rings (a + b)*x """ @@ -1153,10 +1166,12 @@ def expand(self): sage: x + s Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Multivariate Polynomial Ring in x, y, z over Integer Ring' and 'Multivariate Polynomial Ring in y, s over Rational Field' + TypeError: unsupported operand parent(s) for +: + '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) - sage: R.gen(0) + S.gen(0) + sage: S = PolynomialRing(GF(5), 'x', 20) # optional - sage.rings.finite_rings + sage: R.gen(0) + S.gen(0) # optional - sage.rings.finite_rings 2*x0 """ if len(self.vars) <= 1: @@ -1203,7 +1218,7 @@ class InfinitePolynomialFunctor(ConstructionFunctor): sage: B. = PolynomialRing(QQ, order='lex') sage: B.construction() (MPoly[x,y,a_3,a_1], Rational Field) - sage: A.construction()[0]*B.construction()[0] + sage: A.construction()[0] * B.construction()[0] InfPoly{[a,b], "lex", "dense"}(MPoly[x,y](...)) Apparently the variables `a_1,a_3` of the polynomial ring are merged with the variables @@ -1211,7 +1226,8 @@ class InfinitePolynomialFunctor(ConstructionFunctor): However, if the polynomial ring was given a different ordering, merging would not be allowed, resulting in a name conflict:: - sage: A.construction()[0]*PolynomialRing(QQ,names=['x','y','a_3','a_1']).construction()[0] + sage: R = PolynomialRing(QQ, names=['x','y','a_3','a_1']) + sage: A.construction()[0] * R.construction()[0] Traceback (most recent call last): ... CoercionException: Incompatible term orders lex, degrevlex @@ -1219,25 +1235,30 @@ class InfinitePolynomialFunctor(ConstructionFunctor): In an infinite polynomial ring with generator `a_\ast`, the variable `a_3` will always be greater than the variable `a_1`. Hence, the orders are incompatible in the next example as well:: - sage: A.construction()[0]*PolynomialRing(QQ,names=['x','y','a_1','a_3'], order='lex').construction()[0] + sage: R = PolynomialRing(QQ, names=['x','y','a_1','a_3'], order='lex') + sage: A.construction()[0] * R.construction()[0] Traceback (most recent call last): ... - CoercionException: Overlapping variables (('a', 'b'),['a_1', 'a_3']) are incompatible + CoercionException: Overlapping variables (('a', 'b'),['a_1', 'a_3']) + are incompatible Another requirement is that after merging the order of the remaining variables must be unique. This is not the case in the following example, since it is not clear whether the variables `x,y` should be greater or smaller than the variables `b_\ast`:: - sage: A.construction()[0]*PolynomialRing(QQ,names=['a_3','a_1','x','y'], order='lex').construction()[0] + sage: R = PolynomialRing(QQ, names=['a_3','a_1','x','y'], order='lex') + sage: A.construction()[0] * R.construction()[0] Traceback (most recent call last): ... - CoercionException: Overlapping variables (('a', 'b'),['a_3', 'a_1']) are incompatible + CoercionException: Overlapping variables (('a', 'b'),['a_3', 'a_1']) + are incompatible Since the construction functors are actually used to construct infinite polynomial rings, the following result is no surprise:: sage: C. = InfinitePolynomialRing(B); C - Infinite polynomial ring in a, b over Multivariate Polynomial Ring in x, y over Rational Field + Infinite polynomial ring in a, b + over Multivariate Polynomial Ring in x, y over Rational Field There is also an overlap in the next example:: @@ -1472,8 +1493,8 @@ def merge(self, other): EXAMPLES:: - sage: X. = InfinitePolynomialRing(QQ,implementation='sparse') - sage: Y. = InfinitePolynomialRing(QQ,order='degrevlex') + sage: X. = InfinitePolynomialRing(QQ, implementation='sparse') + sage: Y. = InfinitePolynomialRing(QQ, order='degrevlex') sage: X.construction() [InfPoly{[x,y], "lex", "sparse"}, Rational Field] sage: Y.construction() @@ -1525,11 +1546,13 @@ def expand(self): EXAMPLES:: - sage: F = InfinitePolynomialRing(QQ, ['x','y'],order='degrevlex').construction()[0]; F + sage: A = InfinitePolynomialRing(QQ, ['x','y'], order='degrevlex') + sage: F = A.construction()[0]; F InfPoly{[x,y], "degrevlex", "dense"} sage: F.expand() [InfPoly{[y], "degrevlex", "dense"}, InfPoly{[x], "degrevlex", "dense"}] - sage: F = InfinitePolynomialRing(QQ, ['x','y','z'],order='degrevlex').construction()[0]; F + sage: A = InfinitePolynomialRing(QQ, ['x','y','z'], order='degrevlex') + sage: F = A.construction()[0]; F InfPoly{[x,y,z], "degrevlex", "dense"} sage: F.expand() [InfPoly{[z], "degrevlex", "dense"}, @@ -1551,23 +1574,27 @@ class MatrixFunctor(ConstructionFunctor): EXAMPLES:: - sage: MS = MatrixSpace(ZZ,2, 3) - sage: F = MS.construction()[0]; F + sage: MS = MatrixSpace(ZZ, 2, 3) # optional - sage.modules + sage: F = MS.construction()[0]; F # optional - sage.modules MatrixFunctor - sage: MS = MatrixSpace(ZZ,2) - sage: F = MS.construction()[0]; F + sage: MS = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: F = MS.construction()[0]; F # optional - sage.modules MatrixFunctor - 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) - Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field + sage: P. = QQ[] # optional - sage.modules + sage: R = F(P); R # optional - sage.modules + 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 + Ring endomorphism + of Full MatrixSpace of 2 by 2 dense matrices + over Multivariate Polynomial Ring in x, y over Rational Field Defn: Induced from base ring by - Ring endomorphism of Multivariate Polynomial Ring in x, y over Rational Field + Ring endomorphism + 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]) - sage: F(f)(M) + sage: M = R([x, y, x*y, x + y]) # optional - sage.modules + sage: F(f)(M) # optional - sage.modules [ x + y x - y] [x^2 - y^2 2*x] @@ -1579,21 +1606,21 @@ def __init__(self, nrows, ncols, is_sparse=False): TESTS:: sage: from sage.categories.pushout import MatrixFunctor - sage: F = MatrixFunctor(2,3) - sage: F == MatrixSpace(ZZ,2,3).construction()[0] + sage: F = MatrixFunctor(2, 3) # optional - sage.modules + sage: F == MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules True - sage: F.codomain() + sage: F.codomain() # optional - sage.modules Category of commutative additive groups - sage: R = MatrixSpace(ZZ,2,2).construction()[0] - sage: R.codomain() + sage: R = MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules + sage: R.codomain() # optional - sage.modules Category of rings - sage: F(ZZ) + sage: F(ZZ) # optional - sage.modules Full MatrixSpace of 2 by 3 dense matrices over Integer Ring - sage: F(ZZ) in F.codomain() + sage: F(ZZ) in F.codomain() # optional - sage.modules True - sage: R(GF(2)) + sage: R(GF(2)) # optional - sage.rings.finite_rings sage.modules Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 2 - sage: R(GF(2)) in R.codomain() + sage: R(GF(2)) in R.codomain() # optional - sage.rings.finite_rings sage.modules True """ if nrows == ncols: @@ -1613,10 +1640,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] - sage: F(RR) # indirect doctest + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F(RR) # indirect doctest # optional - sage.modules Full MatrixSpace of 2 by 3 dense matrices over Real Field with 53 bits of precision - sage: F(RR) in F.codomain() + sage: F(RR) in F.codomain() # optional - sage.modules True """ @@ -1627,10 +1654,10 @@ def __eq__(self, other): """ TESTS:: - sage: F = MatrixSpace(ZZ,2,3).construction()[0] - sage: F == loads(dumps(F)) + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F == loads(dumps(F)) # optional - sage.modules True - sage: F == MatrixSpace(ZZ,2,2).construction()[0] + sage: F == MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules False """ if isinstance(other, MatrixFunctor): @@ -1643,10 +1670,10 @@ def __ne__(self, other): EXAMPLES:: - sage: F = MatrixSpace(ZZ,2,3).construction()[0] - sage: F != loads(dumps(F)) + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F != loads(dumps(F)) # optional - sage.modules False - sage: F != MatrixSpace(ZZ,2,2).construction()[0] + sage: F != MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules True """ return not (self == other) @@ -1661,20 +1688,20 @@ def merge(self, other): EXAMPLES:: - 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) + 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 MatrixFunctor - sage: F13 = F1.merge(F3) - sage: F13.is_sparse + sage: F13 = F1.merge(F3) # optional - sage.modules + sage: F13.is_sparse # optional - sage.modules False - sage: F1.is_sparse + sage: F1.is_sparse # optional - sage.modules False - sage: F3.is_sparse + sage: F3.is_sparse # optional - sage.modules True - sage: F3.merge(F3).is_sparse + sage: F3.merge(F3).is_sparse # optional - sage.modules True """ @@ -1698,16 +1725,18 @@ class LaurentPolynomialFunctor(ConstructionFunctor): Univariate Laurent Polynomial Ring in t over Rational Field sage: K. = LaurentPolynomialRing(ZZ) sage: F(K) - Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in x over Integer Ring + Univariate Laurent Polynomial Ring in t + over Univariate Laurent Polynomial Ring in x over Integer Ring sage: P. = ZZ[] - sage: f = P.hom([x+2*y,3*x-y],P) + sage: f = P.hom([x + 2*y, 3*x - y],P) sage: F(f) - Ring endomorphism of Univariate Laurent Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Integer Ring + Ring endomorphism of Univariate Laurent Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Integer Ring Defn: Induced from base ring by Ring endomorphism of Multivariate Polynomial Ring in x, y over Integer Ring Defn: x |--> x + 2*y y |--> 3*x - y - sage: F(f)(x*F(P).gen()^-2+y*F(P).gen()^3) + sage: F(f)(x*F(P).gen()^-2 + y*F(P).gen()^3) (x + 2*y)*t^-2 + (3*x - y)*t^3 """ @@ -1824,10 +1853,11 @@ def merge(self, other): sage: F2 = LaurentPolynomialFunctor('t', multi_variate=True) sage: F1.merge(F2) LaurentPolynomialFunctor - sage: F1.merge(F2)(LaurentPolynomialRing(GF(2),'a')) + sage: F1.merge(F2)(LaurentPolynomialRing(GF(2), 'a')) # optional - sage.rings.finite_rings Multivariate Laurent Polynomial Ring in a, t over Finite Field of size 2 - sage: F1.merge(F1)(LaurentPolynomialRing(GF(2),'a')) - Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in a over Finite Field of size 2 + sage: F1.merge(F1)(LaurentPolynomialRing(GF(2), 'a')) # optional - sage.rings.finite_rings + Univariate Laurent Polynomial Ring in t over + Univariate Laurent Polynomial Ring in a over Finite Field of size 2 """ if self == other or isinstance(other, PolynomialFunctor) and self.var == other.var: @@ -1842,11 +1872,12 @@ class VectorFunctor(ConstructionFunctor): EXAMPLES:: - sage: F = (ZZ^3).construction()[0] - sage: F + sage: F = (ZZ^3).construction()[0] # optional - sage.modules + sage: F # optional - sage.modules VectorFunctor - sage: F(GF(2)['t']) - Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) + sage: F(GF(2)['t']) # optional - sage.rings.finite_rings sage.modules + Ambient free module of rank 3 + 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 @@ -1866,21 +1897,21 @@ def __init__(self, n=None, is_sparse=False, inner_product_matrix=None, *, TESTS:: sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: F1.domain() + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules + sage: F1.domain() # optional - sage.modules Category of commutative rings - sage: F1.codomain() + sage: F1.codomain() # optional - sage.modules Category of commutative additive groups - sage: M1 = F1(ZZ) - sage: M1.is_sparse() + sage: M1 = F1(ZZ) # optional - sage.modules + sage: M1.is_sparse() # optional - sage.modules False - sage: v = M1([3, 2, 1]) - sage: v*Matrix(3,3,range(9))*v.column() + sage: v = M1([3, 2, 1]) # optional - sage.modules + sage: v * Matrix(3, 3, range(9)) * v.column() # optional - sage.modules (96) - sage: v.inner_product(v) + sage: v.inner_product(v) # optional - sage.modules 96 sage: F2 = VectorFunctor(3, is_sparse=True) - sage: M2 = F2(QQ); M2; M2.is_sparse() + sage: M2 = F2(QQ); M2; M2.is_sparse() # optional - sage.modules Sparse vector space of dimension 3 over Rational Field True @@ -1908,28 +1939,28 @@ def _apply_functor(self, R): TESTS:: sage: from sage.categories.pushout import VectorFunctor, pushout - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: M1 = F1(ZZ) # indirect doctest - sage: M1.is_sparse() + 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 False - sage: v = M1([3, 2, 1]) - sage: v*Matrix(3,3,range(9))*v.column() + sage: v = M1([3, 2, 1]) # optional - sage.modules + sage: v * Matrix(3, 3, range(9)) * v.column() # optional - sage.modules (96) - sage: v.inner_product(v) + sage: v.inner_product(v) # optional - sage.modules 96 - sage: F2 = VectorFunctor(3, is_sparse=True) - sage: M2 = F2(QQ); M2; M2.is_sparse() + sage: F2 = VectorFunctor(3, is_sparse=True) # optional - sage.modules + sage: M2 = F2(QQ); M2; M2.is_sparse() # optional - sage.modules Sparse vector space of dimension 3 over Rational Field True - sage: v = M2([3, 2, 1]) - sage: v.inner_product(v) + sage: v = M2([3, 2, 1]) # optional - sage.modules + sage: v.inner_product(v) # optional - sage.modules 14 - sage: M = FreeModule(ZZ, 4, with_basis=None, name='M') - sage: latex(M) + sage: M = FreeModule(ZZ, 4, with_basis=None, name='M') # optional - sage.modules + sage: latex(M) # optional - sage.modules M - sage: M_QQ = pushout(M, QQ) - sage: latex(M_QQ) + sage: M_QQ = pushout(M, QQ) # optional - sage.modules + sage: latex(M_QQ) # optional - sage.modules M \otimes \Bold{Q} """ @@ -1957,10 +1988,10 @@ def _apply_functor_to_morphism(self, f): TESTS:: - sage: F = (ZZ^3).construction()[0] + sage: F = (ZZ^3).construction()[0] # optional - sage.modules sage: P. = ZZ[] - sage: f = P.hom([x+2*y,3*x-y],P) - sage: F(f) # indirect doctest + sage: f = P.hom([x + 2*y, 3*x - y], P) + sage: F(f) # indirect doctest # optional - sage.modules Traceback (most recent call last): ... NotImplementedError: Cannot create induced morphisms of free modules yet @@ -1975,13 +2006,13 @@ def __eq__(self, other): TESTS:: sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: F2 = (ZZ^3).construction()[0] - sage: F1 == F2 + 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 False - sage: F1(QQ) == F2(QQ) + sage: F1(QQ) == F2(QQ) # optional - sage.modules False - sage: F1 == loads(dumps(F1)) + sage: F1 == loads(dumps(F1)) # optional - sage.modules True """ if isinstance(other, VectorFunctor): @@ -2000,13 +2031,13 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: F2 = (ZZ^3).construction()[0] - sage: F1 != F2 + 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 True - sage: F1(QQ) != F2(QQ) + sage: F1(QQ) != F2(QQ) # optional - sage.modules True - sage: F1 != loads(dumps(F1)) + sage: F1 != loads(dumps(F1)) # optional - sage.modules False """ return not (self == other) @@ -2022,19 +2053,19 @@ def merge(self, other): Two modules without explicitly given inner product allow coercion:: - sage: M1 = QQ^3 + sage: M1 = QQ^3 # optional - sage.modules sage: P. = ZZ[] - sage: M2 = FreeModule(P,3) - sage: M1([1,1/2,1/3]) + M2([t,t^2+t,3]) # indirect doctest + 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 (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))) - sage: M1([1,1/2,1/3]) + M3([t,t^2+t,3]) + 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 (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() + sage: (M1([1,1/2,1/3]) + M3([t,t^2+t,3])).parent().inner_product_matrix() # optional - sage.modules [0 1 2] [3 4 5] [6 7 8] @@ -2045,19 +2076,22 @@ 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)) - sage: M4 == M1 + sage: M4 = FreeModule(QQ, 3, inner_product_matrix=Matrix(3, 3, 1)) # optional - sage.modules + sage: M4 == M1 # optional - sage.modules True - sage: M4.inner_product_matrix() == M1.inner_product_matrix() + sage: M4.inner_product_matrix() == M1.inner_product_matrix() # optional - sage.modules True - sage: M4([1,1/2,1/3]) + M3([t,t^2+t,3]) # indirect doctest + sage: M4([1,1/2,1/3]) + M3([t,t^2+t,3]) # indirect doctest # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Ambient quadratic space of dimension 3 over Rational Field + TypeError: unsupported operand parent(s) for +: + 'Ambient quadratic space of dimension 3 over Rational Field Inner product matrix: [1 0 0] [0 1 0] - [0 0 1]' and 'Ambient free quadratic module of rank 3 over the integral domain Univariate Polynomial Ring in t over Integer Ring + [0 0 1]' and + 'Ambient free quadratic module of rank 3 over the integral domain + Univariate Polynomial Ring in t over Integer Ring Inner product matrix: [0 1 2] [3 4 5] @@ -2066,14 +2100,17 @@ def merge(self, other): Names are removed when they conflict:: sage: from sage.categories.pushout import VectorFunctor, pushout - 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) - Rank-4 free module over the Univariate Polynomial Ring in x over Integer Ring - sage: pushout(pushout(M_ZZx, N_ZZx), QQ) - Rank-4 free module over the Univariate Polynomial Ring in x over Rational Field + 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 + 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 + 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 + Rank-4 free module + over the Univariate Polynomial Ring in x over Rational Field """ if not isinstance(other, VectorFunctor): return None @@ -2143,14 +2180,14 @@ class SubspaceFunctor(ConstructionFunctor): EXAMPLES:: - sage: M = ZZ^3 - sage: S = M.submodule([(1,2,3),(4,5,6)]); S + sage: M = ZZ^3 # optional - sage.modules + sage: S = M.submodule([(1,2,3), (4,5,6)]); S # optional - sage.modules 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] - sage: F(GF(2)^3) + sage: F = S.construction()[0] # optional - sage.modules + sage: F(GF(2)^3) # optional - sage.rings.finite_rings sage.modules Vector space of degree 3 and dimension 2 over Finite Field of size 2 User basis matrix: [1 0 1] @@ -2172,9 +2209,9 @@ def __init__(self, basis): TESTS:: sage: from sage.categories.pushout import SubspaceFunctor - sage: M = ZZ^3 - sage: F = SubspaceFunctor([M([1,2,3]),M([4,5,6])]) - sage: F(GF(5)^3) + 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 Vector space of degree 3 and dimension 2 over Finite Field of size 5 User basis matrix: [1 2 3] @@ -2194,14 +2231,14 @@ def _apply_functor(self, ambient): TESTS:: - sage: M = ZZ^3 - sage: S = M.submodule([(1,2,3),(4,5,6)]); S + sage: M = ZZ^3 # optional - sage.modules + sage: S = M.submodule([(1,2,3), (4,5,6)]); S # optional - sage.modules 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] - sage: F(GF(2)^3) # indirect doctest + sage: F = S.construction()[0] # optional - sage.modules + sage: F(GF(2)^3) # indirect doctest # optional - sage.rings.finite_rings sage.modules Vector space of degree 3 and dimension 2 over Finite Field of size 2 User basis matrix: [1 0 1] @@ -2215,10 +2252,10 @@ def _apply_functor_to_morphism(self, f): TESTS:: - 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 + 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 Traceback (most recent call last): ... NotImplementedError: Cannot create morphisms of free sub-modules yet @@ -2229,32 +2266,32 @@ def __eq__(self, other): """ TESTS:: - 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)) + 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 True The ``span`` method automatically transforms the given basis into echelon form. The bases look like that:: - sage: F1.basis + sage: F1.basis # optional - sage.modules sage.rings.finite_rings [ (1, 0, 4), (0, 1, 2) ] - sage: F2.basis + sage: F2.basis # optional - sage.modules [ (1, 2, 3), (0, 3, 6) ] - sage: F3.basis + sage: F3.basis # optional - sage.modules [ (1, 0, -1), (0, 1, 2) ] - sage: F4.basis + sage: F4.basis # optional - sage.modules [ (1, 0, -1), (0, 1, 2) @@ -2264,18 +2301,18 @@ def __eq__(self, other): The basis of ``F2`` is modulo 5 different from the other bases. So, we have:: - sage: F1 != F2 != F3 + sage: F1 != F2 != F3 # optional - sage.modules sage.rings.finite_rings 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 + sage: F1 == F3 # optional - sage.modules sage.rings.finite_rings False But there are coercions from ``ZZ^3`` to ``QQ^3`` and ``GF(5)^3``, thus:: - sage: F1 == F4 == F3 + sage: F1 == F4 == F3 # optional - sage.modules sage.rings.finite_rings True """ @@ -2301,8 +2338,8 @@ def __ne__(self, other): EXAMPLES:: - sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] - sage: F1 != loads(dumps(F1)) + 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 False """ return not (self == other) @@ -2315,17 +2352,18 @@ def merge(self, other): EXAMPLES:: - 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) + 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 SubspaceFunctor - sage: F1.merge(F2)(GF(5)^3) == S1+S2 + sage: F1.merge(F2)(GF(5)^3) == S1 + S2 # optional - sage.modules sage.rings.finite_rings True - 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 + sage: F1.merge(F2)(GF(5)['t']^3) # optional - sage.modules sage.rings.finite_rings + Free module of degree 3 and rank 3 + over Univariate Polynomial Ring in t over Finite Field of size 5 User basis matrix: [1 0 0] [0 1 0] @@ -2334,12 +2372,13 @@ def merge(self, other): TESTS:: sage: P. = ZZ[] - 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 + 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 (2, 3, (-12*t - 1)/(-2*t)) - sage: v.parent() - Vector space of degree 3 and dimension 3 over Fraction Field of Univariate Polynomial Ring in t over Integer Ring + sage: v.parent() # optional - sage.modules + Vector space of degree 3 and dimension 3 + over Fraction Field of Univariate Polynomial Ring in t over Integer Ring User basis matrix: [1 0 0] [0 1 0] @@ -2384,14 +2423,15 @@ class FractionField(ConstructionFunctor): Category of integral domains sage: F.codomain() Category of fields - sage: F(GF(5)) is GF(5) + sage: F(GF(5)) is GF(5) # optional - sage.rings.finite_rings True sage: F(ZZ['t']) Fraction Field of Univariate Polynomial Ring in t over Integer Ring sage: P. = QQ[] sage: f = P.hom([x+2*y,3*x-y],P) sage: F(f) - Ring endomorphism of Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field + Ring endomorphism of + Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x + 2*y y |--> 3*x - y sage: F(f)(1/x) @@ -2424,8 +2464,9 @@ def _apply_functor(self, R): TESTS:: sage: F = QQ.construction()[0] - sage: F(GF(5)['t']) # indirect doctest - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 + sage: F(GF(5)['t']) # indirect doctest # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 """ return R.fraction_field() @@ -2436,15 +2477,15 @@ class CompletionFunctor(ConstructionFunctor): EXAMPLES:: - sage: R = Zp(5) - sage: R + sage: R = Zp(5) # optional - sage.rings.padics + sage: R # optional - sage.rings.padics 5-adic Ring with capped relative precision 20 - sage: F1 = R.construction()[0] - sage: F1 + sage: F1 = R.construction()[0] # optional - sage.rings.padics + sage: F1 # optional - sage.rings.padics Completion[5, prec=20] - sage: F1(ZZ) is R + sage: F1(ZZ) is R # optional - sage.rings.padics True - sage: F1(QQ) + sage: F1(QQ) # optional - sage.rings.padics 5-adic Field with capped relative precision 20 sage: F2 = RR.construction()[0] sage: F2 @@ -2456,16 +2497,16 @@ class CompletionFunctor(ConstructionFunctor): sage: Px Power Series Ring in x over Integer Ring sage: F3 = Px.construction()[0] - sage: F3(GF(3)['x']) + sage: F3(GF(3)['x']) # optional - sage.rings.finite_rings Power Series Ring in x over Finite Field of size 3 TESTS:: - sage: R1. = Zp(5,prec=20)[] - sage: R2 = Qp(5,prec=40) - sage: R2(1) + a + 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 (1 + O(5^20))*a + 1 + O(5^40) - sage: 1/2 + a + sage: 1/2 + a # optional - sage.rings.padics (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) """ @@ -2496,14 +2537,14 @@ def __init__(self, p, prec, extras=None): TESTS:: sage: from sage.categories.pushout import CompletionFunctor - sage: F1 = CompletionFunctor(5,100) - sage: F1(QQ) + sage: F1 = CompletionFunctor(5, 100) # optional - sage.rings.padics + sage: F1(QQ) # optional - sage.rings.padics 5-adic Field with capped relative precision 100 - sage: F1(ZZ) + sage: F1(ZZ) # optional - sage.rings.padics 5-adic Ring with capped relative precision 100 - sage: F1.type is None + sage: F1.type is None # optional - sage.rings.padics True - sage: sorted(F1.extras.items()) + sage: sorted(F1.extras.items()) # optional - sage.rings.padics [] sage: F2 = RR.construction()[0] sage: F2 @@ -2535,7 +2576,7 @@ def _repr_(self): """ TESTS:: - sage: Zp(7).construction() # indirect doctest + sage: Zp(7).construction() # indirect doctest # optional - sage.rings.padics (Completion[7, prec=20], Integer Ring) sage: RR.construction() # indirect doctest @@ -2549,11 +2590,11 @@ def _apply_functor(self, R): TESTS:: - sage: R = Zp(5) - sage: F1 = R.construction()[0] - sage: F1(ZZ) is R # indirect doctest + 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 True - sage: F1(QQ) + sage: F1(QQ) # optional - sage.rings.padics 5-adic Field with capped relative precision 20 """ @@ -2592,19 +2633,19 @@ def __eq__(self, other): TESTS:: - 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 + 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 True - sage: F1 == F2 + sage: F1 == F2 # optional - sage.rings.padics True - sage: F1(QQ) == F2(QQ) + sage: F1(QQ) == F2(QQ) # optional - sage.rings.padics False - sage: R3 = Zp(7) - sage: F3 = R3.construction()[0] - sage: F1 == F3 + sage: R3 = Zp(7) # optional - sage.rings.padics + sage: F3 = R3.construction()[0] # optional - sage.rings.padics + sage: F1 == F3 # optional - sage.rings.padics False """ if isinstance(other, CompletionFunctor): @@ -2617,19 +2658,19 @@ def __ne__(self, other): EXAMPLES:: - 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 + 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 False - sage: F1 != F2 + sage: F1 != F2 # optional - sage.rings.padics False - sage: F1(QQ) != F2(QQ) + sage: F1(QQ) != F2(QQ) # optional - sage.rings.padics True - sage: R3 = Zp(7) - sage: F3 = R3.construction()[0] - sage: F1 != F3 + sage: R3 = Zp(7) # optional - sage.rings.padics + sage: F3 = R3.construction()[0] # optional - sage.rings.padics + sage: F1 != F3 # optional - sage.rings.padics True """ return not (self == other) @@ -2647,15 +2688,15 @@ def merge(self, other): EXAMPLES:: - sage: R1. = Zp(5,prec=20)[] - sage: R2 = Qp(5,prec=40) - sage: R2(1)+a # indirect doctest + 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 (1 + O(5^20))*a + 1 + O(5^40) - sage: R3 = RealField(30) - sage: R4 = RealField(50) - sage: R3(1) + R4(1) # indirect doctest + 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 2.0000000 - sage: (R3(1) + R4(1)).parent() + sage: (R3(1) + R4(1)).parent() # optional - sage.rings.padics Real Field with 30 bits of precision TESTS: @@ -2665,22 +2706,23 @@ def merge(self, other): sage: RIF(1) > RR(1) Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for >: 'Real Interval Field with 53 bits of precision' and 'Real Field with 53 bits of precision' + TypeError: unsupported operand parent(s) for >: + 'Real Interval Field with 53 bits of precision' and 'Real Field with 53 bits of precision' We check that various pushouts work:: sage: R0 = RealIntervalField(30) sage: R1 = RealIntervalField(30, sci_not=True) sage: R2 = RealIntervalField(53) - sage: R3 = RealIntervalField(53, sci_not = True) + sage: R3 = RealIntervalField(53, sci_not=True) sage: R4 = RealIntervalField(90) - sage: R5 = RealIntervalField(90, sci_not = True) + sage: R5 = RealIntervalField(90, sci_not=True) sage: R6 = RealField(30) sage: R7 = RealField(30, sci_not=True) - sage: R8 = RealField(53, rnd = 'RNDD') - sage: R9 = RealField(53, sci_not = True, rnd = 'RNDZ') - sage: R10 = RealField(53, sci_not = True) - sage: R11 = RealField(90, sci_not = True, rnd = 'RNDZ') + sage: R8 = RealField(53, rnd='RNDD') + sage: R9 = RealField(53, sci_not=True, rnd='RNDZ') + sage: R10 = RealField(53, sci_not=True) + sage: R11 = RealField(90, sci_not=True, rnd='RNDZ') sage: Rlist = [R0,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11] sage: from sage.categories.pushout import pushout sage: pushouts = [R0,R0,R0,R1,R0,R1,R0,R1,R0,R1,R1,R1,R1,R1,R1,R1,R1,R1,R1,R1,R1,R1,R1,R1,R0,R1,R2,R2,R2,R3,R0,R1,R2,R3,R3,R3,R1,R1,R3,R3,R3,R3,R1,R1,R3,R3,R3,R3,R0,R1,R2,R3,R4,R4,R0,R1,R2,R3,R3,R5,R1,R1,R3,R3,R5,R5,R1,R1,R3,R3,R3,R5,R0,R1,R0,R1,R0,R1,R6,R6,R6,R7,R7,R7,R1,R1,R1,R1,R1,R1,R7,R7,R7,R7,R7,R7,R0,R1,R2,R3,R2,R3,R6,R7,R8,R9,R10,R9,R1,R1,R3,R3,R3,R3,R7,R7,R9,R9,R10,R9,R1,R1,R3,R3,R3,R3,R7,R7,R10,R10,R10,R10,R1,R1,R3,R3,R5,R5,R7,R7,R9,R9,R10,R11] @@ -2689,18 +2731,20 @@ def merge(self, other): :: - 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: 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: 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,P5,P5,P5,P5,P7,P7,P6,P7,P6,P7,P6,P7,P7,P7,P7,P7,P7,P7] - sage: all(P is Q for P, Q in zip(pushouts, [pushout(a, b) for a in Plist for b in Plist])) + sage: pushouts = [P2,P3,P4,P5,P6,P7,P3,P3,P5,P5,P7,P7,P4,P5,P4,P5,P6,P7, # optional - sage.rings.padics + ....: 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 + ....: for P, Q in zip(pushouts, [pushout(a, b) for a in Plist for b in Plist])) True """ if self == other: # both are Completion functors with the same p @@ -2742,9 +2786,9 @@ def commutes(self, other): EXAMPLES:: - sage: F1 = Zp(5).construction()[0] + sage: F1 = Zp(5).construction()[0] # optional - sage.rings.padics sage: F2 = QQ.construction()[0] - sage: F1.commutes(F2) + sage: F1.commutes(F2) # optional - sage.rings.padics True TESTS: @@ -2771,10 +2815,12 @@ def commutes(self, other): Ambiguous base extension error raised):: sage: from sage.categories.pushout import pushout - sage: pushout(Qp(7),RLF) + sage: pushout(Qp(7), RLF) # optional - sage.rings.padics Traceback (most recent call last): ... - CoercionException: Don't know how to apply Completion[+Infinity, prec=+Infinity] to 7-adic Ring with capped relative precision 20 + CoercionException: Don't know how to + apply Completion[+Infinity, prec=+Infinity] + to 7-adic Ring with capped relative precision 20 """ return isinstance(other, FractionField) @@ -2792,17 +2838,19 @@ class QuotientFunctor(ConstructionFunctor): EXAMPLES:: sage: P. = ZZ[] - 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']) + 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 + 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 True - sage: F(QQ['x','y','z']) + sage: F(QQ['x','y','z']) # optional - sage.rings.finite_rings 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']) + 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 Traceback (most recent call last): ... TypeError: Could not find a mapping of the passed element to this ring. @@ -2831,21 +2879,25 @@ 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) - Univariate Quotient Polynomial Ring in tbar over Integer Ring with modulus t^2 + 5 - sage: F(QQ['t']) - 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) - Univariate Quotient Polynomial Ring in s over Integer Ring with modulus t^2 + 5 - sage: F(QQ['t']) - 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) + sage: F = QuotientFunctor([5 + t^2] * P) + sage: F(P) # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in tbar + over Integer Ring with modulus t^2 + 5 + sage: F(QQ['t']) # optional - sage.rings.finite_rings + 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 + Univariate Quotient Polynomial Ring in s + over Integer Ring with modulus t^2 + 5 + sage: F(QQ['t']) # optional - sage.rings.finite_rings + 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 Finite Field of size 5 - sage: F = QuotientFunctor([5]*ZZ) - sage: F(ZZ) + sage: F = QuotientFunctor([5] * ZZ) + sage: F(ZZ) # optional - sage.rings.finite_rings Ring of integers modulo 5 """ @@ -2872,11 +2924,12 @@ def _apply_functor(self, R): TESTS:: sage: P. = ZZ[] - sage: Q = P.quo([2+x^2,3*x+y^2]) - sage: F = Q.construction()[0]; F + 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 QuotientFunctor - 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) + sage: F(QQ['x','y']) # indirect doctest # optional - sage.rings.finite_rings + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + 2, y^2 + 3*x) Note that the ``quo()`` method of a field used to return the integer zero. That strange behaviour was removed in github @@ -2919,14 +2972,14 @@ def __eq__(self, other): TESTS:: sage: P. = QQ[] - 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)) + 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 True sage: P2. = QQ[] - sage: F == P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + 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 False sage: P3. = ZZ[] - sage: F == P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + 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 True """ if not isinstance(other, QuotientFunctor): @@ -2944,14 +2997,14 @@ def __ne__(self, other): EXAMPLES:: sage: P. = QQ[] - 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)) + 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 False sage: P2. = QQ[] - sage: F != P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + 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 True sage: P3. = ZZ[] - sage: F != P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + 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 False """ return not (self == other) @@ -2970,15 +3023,16 @@ def merge(self, other): EXAMPLES:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) + 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: from sage.categories.pushout import pushout - sage: pushout(Q1,Q2) # indirect doctest - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^4 + 2*x^2 + 1 + sage: pushout(Q1,Q2) # indirect doctest # optional - sage.rings.finite_rings + 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)) + sage: pushout(GF(5), Integers(5)) # optional - sage.rings.finite_rings Finite Field of size 5 """ @@ -3038,65 +3092,72 @@ class AlgebraicExtensionFunctor(ConstructionFunctor): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F(ZZ['t']) - Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in t over Integer Ring with modulus a^3 + a^2 + 1 + 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 + Univariate Quotient Polynomial Ring in a + over Univariate Polynomial Ring in t over Integer Ring + with modulus a^3 + a^2 + 1 Note that, even if a field is algebraically closed, the algebraic extension will be constructed as the quotient of a univariate polynomial ring:: - sage: F(CC) - 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) - Univariate Quotient Polynomial Ring in a over Real Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 + sage: F(CC) # optional - 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 + Univariate Quotient Polynomial Ring in a + over Real Field with 53 bits of precision + with modulus a^3 + a^2 + 1.00000000000000 Note that the construction functor of a number field applied to the integers returns an order (not necessarily maximal) of that field, similar to the behaviour of ``ZZ.extension(...)``:: - sage: F(ZZ) + sage: F(ZZ) # optional - 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: x = polygen(QQ, 'x') - 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 + 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 + 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 True Special cases are made for cyclotomic fields and residue fields:: - sage: C = CyclotomicField(8) - sage: F,R = C.construction() - sage: F + 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 AlgebraicExtensionFunctor - sage: R + sage: R # optional - sage.rings.number_field Rational Field - sage: F(R) + sage: F(R) # optional - sage.rings.number_field Cyclotomic Field of order 8 and degree 4 - sage: F(ZZ) + sage: F(ZZ) # optional - sage.rings.number_field Maximal Order in Cyclotomic Field of order 8 and degree 4 :: - sage: K. = CyclotomicField(7) - sage: P = K.factor(17)[0][0] - sage: k = K.residue_field(P) - sage: F, R = k.construction() - sage: F + 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 AlgebraicExtensionFunctor - sage: R + sage: R # optional - sage.rings.number_field Cyclotomic Field of order 7 and degree 6 - sage: F(R) is k + sage: F(R) is k # optional - sage.rings.number_field True - sage: F(ZZ) + sage: F(ZZ) # optional - sage.rings.number_field Residue field of Integers modulo 17 - sage: F(CyclotomicField(49)) + sage: F(CyclotomicField(49)) # optional - sage.rings.number_field Residue field in zbar of Fractional ideal (17) """ @@ -3158,23 +3219,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]) - sage: F2 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [0]) - sage: F1==F2 + 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 False - sage: F1(QQ) + sage: F1(QQ) # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 - x^2 + 1 - sage: F1(QQ).coerce_embedding() - sage: phi = F2(QQ).coerce_embedding().__copy__(); phi + sage: F1(QQ).coerce_embedding() # optional - sage.rings.number_field + sage: phi = F2(QQ).coerce_embedding().__copy__(); phi # optional - sage.rings.number_field Generic morphism: - From: Number Field in a with defining polynomial x^3 - x^2 + 1 with a = -0.7548776662466928? + 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) + sage: F1(QQ) == F2(QQ) # optional - sage.rings.number_field False - sage: F1(GF(5)) - Univariate Quotient Polynomial Ring in a over Finite Field of size 5 with modulus a^3 + 4*a^2 + 1 - sage: F2(GF(5)) + sage: F1(GF(5)) # optional - sage.rings.finite_rings sage.rings.number_field + 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 Traceback (most recent call last): ... NotImplementedError: ring extension with prescribed embedding is not implemented @@ -3183,38 +3246,38 @@ 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) + sage: F1(ZZ) # optional - 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) - sage: F,R = C.construction() - sage: F + 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 AlgebraicExtensionFunctor - sage: R + sage: R # optional - sage.rings.number_field Rational Field - sage: F(R) + sage: F(R) # optional - sage.rings.number_field Cyclotomic Field of order 8 and degree 4 - sage: F(ZZ) + sage: F(ZZ) # optional - sage.rings.number_field 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: R. = ZZ[] - sage: K. = NumberField(x^2 - 3) - sage: L0. = K.change_names() - sage: L0.structure() + 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 (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() - sage: L1 is L0 + sage: L1 = (b*x).parent().base_ring() # optional - sage.rings.number_field + sage: L1 is L0 # optional - sage.rings.number_field True """ Functor.__init__(self, Rings(), Rings()) @@ -3258,21 +3321,24 @@ def _apply_functor(self, R): TESTS:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F(ZZ) # indirect doctest + 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 Order in Number Field in a with defining polynomial x^3 + x^2 + 1 - 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 - Univariate Quotient Polynomial Ring in a over Real Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 + sage: F(ZZ['t']) # indirect doctest # optional - 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 + sage: F(RR) # indirect doctest # optional - 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 Check that :trac:`13538` is fixed:: - sage: K = Qp(3,3) - sage: R. = K[] - sage: AEF = sage.categories.pushout.AlgebraicExtensionFunctor([a^2-3], ['a'], [None]) - sage: AEF(K) + 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 3-adic Eisenstein Extension Field in a defined by a^2 - 3 """ @@ -3303,19 +3369,19 @@ def __eq__(self, other): TESTS:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F == loads(dumps(F)) + 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 True - sage: K2. = NumberField(x^3 + x^2 + 1, latex_names='a') - sage: F2 = K2.construction()[0] - sage: F2 == F + 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 True - sage: K3. = NumberField(x^3 + x^2 + 1, latex_names='alpha') - sage: F3 = K3.construction()[0] - sage: F3 == F + 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 False """ if not isinstance(other, AlgebraicExtensionFunctor): @@ -3334,9 +3400,9 @@ def __ne__(self, other): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F != loads(dumps(F)) + 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 False """ return not (self == other) @@ -3380,36 +3446,39 @@ 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() - sage: l = GF(3^3, prefix='z'); b = l.gen() - sage: a + b # indirect doctest + 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 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() - sage: (a+b)+c == a+(b+c) # indirect doctest + 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 True sage: from sage.categories.pushout import pushout - sage: n = pushout(k, l) - sage: o = pushout(l, m) - sage: q = pushout(n, o) - sage: q(o(b)) == q(n(b)) # indirect doctest + 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 True Coercion is also available for number fields:: - 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 + 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 -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']) - 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 + 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 + 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 In the previous example, the number field ``L`` becomes the pushout of ``M1`` and ``M2`` since both are provided with an embedding into @@ -3419,14 +3488,16 @@ def merge(self, other): sage: cbrt2 = CDF(2)^(1/3) sage: zeta3 = CDF.zeta(3) - 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) + 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 Traceback (most recent call last): ... - CoercionException: ('Ambiguous Base Extension', Number Field in a with defining polynomial x^3 - 2 with a = -0.6299605249474365? + 1.091123635971722?*I, Number Field in b with defining polynomial x^6 - 2 with b = 1.122462048309373?) + CoercionException: ('Ambiguous Base Extension', Number Field in a with + defining polynomial x^3 - 2 with a = -0.6299605249474365? + 1.091123635971722?*I, + Number Field in b with defining polynomial x^6 - 2 with b = 1.122462048309373?) """ if isinstance(other, AlgebraicClosureFunctor): @@ -3496,10 +3567,10 @@ def __mul__(self, other): TESTS:: sage: P. = QQ[] - 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 + 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 True """ @@ -3528,18 +3599,18 @@ def expand(self): EXAMPLES:: sage: P. = QQ[] - 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 + 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 True - sage: K = NumberField([x^2-2, x^2-3],'a') - sage: F, R = K.construction() - sage: F + 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 AlgebraicExtensionFunctor - sage: L = F.expand(); L + sage: L = F.expand(); L # optional - sage.rings.number_field [AlgebraicExtensionFunctor, AlgebraicExtensionFunctor] - sage: L[-1](QQ) + sage: L[-1](QQ) # optional - sage.rings.number_field Number Field in a1 with defining polynomial x^2 - 3 """ n = len(self.polys) @@ -3559,11 +3630,11 @@ class AlgebraicClosureFunctor(ConstructionFunctor): EXAMPLES:: sage: F = CDF.construction()[0] - sage: F(QQ) + sage: F(QQ) # optional - sage.rings.number_field Algebraic Field sage: F(RR) Complex Field with 53 bits of precision - sage: F(F(QQ)) is F(QQ) + sage: F(F(QQ)) is F(QQ) # optional - sage.rings.number_field True """ @@ -3575,7 +3646,7 @@ def __init__(self): sage: from sage.categories.pushout import AlgebraicClosureFunctor sage: F = AlgebraicClosureFunctor() - sage: F(QQ) + sage: F(QQ) # optional - sage.rings.number_field Algebraic Field sage: F(RR) Complex Field with 53 bits of precision @@ -3592,7 +3663,7 @@ def _apply_functor(self, R): TESTS:: sage: F = CDF.construction()[0] - sage: F(QQ) # indirect doctest + sage: F(QQ) # indirect doctest # optional - sage.rings.number_field Algebraic Field """ try: @@ -3612,10 +3683,10 @@ def merge(self, other): TESTS:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3+x^2+1) - sage: CDF.construction()[0].merge(K.construction()[0]) is None + 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 True - sage: CDF.construction()[0].merge(CDF.construction()[0]) + sage: CDF.construction()[0].merge(CDF.construction()[0]) # optional - sage.rings.number_field AlgebraicClosureFunctor """ @@ -3638,7 +3709,8 @@ def __init__(self, gens, domain): EXAMPLES:: sage: from sage.categories.pushout import PermutationGroupFunctor - sage: PF = PermutationGroupFunctor([PermutationGroupElement([(1,2)])], [1,2]); PF + sage: PF = PermutationGroupFunctor([PermutationGroupElement([(1,2)])], # optional - sage.groups + ....: [1,2]); PF PermutationGroupFunctor[(1,2)] """ Functor.__init__(self, Groups(), Groups()) @@ -3649,9 +3721,9 @@ def _repr_(self): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF, P = P1.construction() - sage: PF + sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups + sage: PF, P = P1.construction() # optional - sage.groups + sage: PF # optional - sage.groups PermutationGroupFunctor[(1,2)] """ return "PermutationGroupFunctor%s" % list(self.gens()) @@ -3660,9 +3732,9 @@ def __call__(self, R): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF, P = P1.construction() - sage: PF(P) + sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups + sage: PF, P = P1.construction() # optional - sage.groups + sage: PF(P) # optional - sage.groups Permutation Group with generators [(1,2)] """ from sage.groups.perm_gps.permgroup import PermutationGroup @@ -3673,9 +3745,9 @@ def gens(self): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF, P = P1.construction() - sage: PF.gens() + sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups + sage: PF, P = P1.construction() # optional - sage.groups + sage: PF.gens() # optional - sage.groups ((1,2),) """ return self._gens @@ -3686,11 +3758,11 @@ def merge(self, other): EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF1, P = P1.construction() - sage: P2 = PermutationGroup([[(1,3)]]) - sage: PF2, P = P2.construction() - sage: PF1.merge(PF2) + 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 PermutationGroupFunctor[(1,2), (1,3)] """ if self.__class__ != other.__class__: @@ -3736,13 +3808,13 @@ 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 + sage: GSym01 = PermutationGroup([[(0,1),(2,),(3,)]]); GSym01 # optional - sage.groups Permutation Group with generators [(0,1)] - sage: GASym01 = PermutationGroup([[(0,1),(2,3)]]); GASym01 + sage: GASym01 = PermutationGroup([[(0,1),(2,3)]]); GASym01 # optional - sage.groups 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): + sage: class TensorIndexAction(Action): # optional - sage.modules ....: def _act_(self, g, x): ....: if isinstance(x, Matrix): ....: if g(0) == 1: @@ -3753,39 +3825,40 @@ class EquivariantSubobjectConstructionFunctor(ConstructionFunctor): ....: else: ....: return x ....: raise NotImplementedError - sage: M = matrix([[1, 2], [3, 4]]); M + sage: M = matrix([[1, 2], [3, 4]]); M # optional - sage.modules [1 2] [3 4] - sage: GSym01_action = TensorIndexAction(GSym01, M.parent()) - sage: GASym01_action = TensorIndexAction(GASym01, M.parent()) - sage: GSym01_action.act(GSym01.0, M) + 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 [1 3] [2 4] - sage: GASym01_action.act(GASym01.0, M) + sage: GASym01_action.act(GASym01.0, M) # optional - sage.groups sage.modules [-1 -3] [-2 -4] - sage: Sym01 = M.parent().invariant_module(GSym01, action=GSym01_action); Sym01 + sage: Sym01 = M.parent().invariant_module(GSym01, action=GSym01_action); Sym01 # optional - sage.groups sage.modules (Permutation Group with generators [(0,1)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: list(Sym01.basis()) + sage: list(Sym01.basis()) # optional - sage.groups sage.modules [B[0], B[1], B[2]] - sage: list(Sym01.basis().map(Sym01.lift)) + sage: list(Sym01.basis().map(Sym01.lift)) # optional - sage.groups sage.modules [ [1 0] [0 1] [0 0] [0 0], [1 0], [0 1] ] - sage: ASym01 = M.parent().invariant_module(GASym01, action=GASym01_action); ASym01 + sage: ASym01 = M.parent().invariant_module(GASym01, action=GASym01_action) # optional - sage.groups sage.modules + sage: ASym01 # optional - sage.groups sage.modules (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()) + sage: list(ASym01.basis()) # optional - sage.groups sage.modules [B[0]] - sage: list(ASym01.basis().map(ASym01.lift)) + sage: list(ASym01.basis().map(ASym01.lift)) # optional - sage.groups sage.modules [ [ 0 1] [-1 0] ] sage: from sage.categories.pushout import pushout - sage: pushout(Sym01, QQ) + sage: pushout(Sym01, QQ) # optional - sage.groups sage.modules (Permutation Group with generators [(0,1)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Rational Field """ @@ -3794,12 +3867,12 @@ def __init__(self, S, action=operator.mul, side='left', """ EXAMPLES:: - 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 + 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 (S3)-invariant submodule of M - sage: I.construction() + sage: I.construction() # optional - sage.groups sage.modules (EquivariantSubobjectConstructionFunctor, Representation of S3 indexed by {1, 2, 3} over Integer Ring) """ @@ -3818,13 +3891,13 @@ def _apply_functor(self, X): TESTS:: sage: from sage.categories.pushout import EquivariantSubobjectConstructionFunctor - sage: M2 = MatrixSpace(QQ, 2); M2 + sage: M2 = MatrixSpace(QQ, 2); M2 # optional - sage.groups sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: F = EquivariantSubobjectConstructionFunctor(M2, - ....: operator.mul, 'left', - ....: operator.mul, 'right'); F + sage: F = EquivariantSubobjectConstructionFunctor(M2, # optional - sage.groups sage.modules + ....: operator.mul, 'left', + ....: operator.mul, 'right'); F EquivariantSubobjectConstructionFunctor - sage: F(M2) + sage: F(M2) # optional - sage.groups sage.modules Traceback (most recent call last): ... NotImplementedError: non-trivial other_action= is not implemented @@ -3843,24 +3916,24 @@ class BlackBoxConstructionFunctor(ConstructionFunctor): EXAMPLES:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FS = BlackBoxConstructionFunctor(singular) - sage: FG + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FS = BlackBoxConstructionFunctor(singular) # optional - sage.libs.singular + sage: FG # optional - sage.libs.gap BlackBoxConstructionFunctor - sage: FG(ZZ) + sage: FG(ZZ) # optional - sage.libs.gap Integers - sage: FG(ZZ).parent() + sage: FG(ZZ).parent() # optional - sage.libs.gap Gap - sage: FS(QQ['t']) + sage: FS(QQ['t']) # optional - 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 + sage: FG == FS # optional - sage.libs.gap sage.libs.singular False - sage: FG == loads(dumps(FG)) + sage: FG == loads(dumps(FG)) # optional - sage.libs.gap True """ rank = 100 @@ -3870,11 +3943,11 @@ def __init__(self, box): TESTS:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # optional - sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic + sage: FM == FG # optional - sage.symbolic False - sage: FM == loads(dumps(FM)) # optional - sage.symbolic + sage: FM == loads(dumps(FM)) # optional - sage.symbolic True """ ConstructionFunctor.__init__(self, Objects(), Objects()) @@ -3891,7 +3964,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 + sage: F(ZZ) # indirect doctest # optional - sage.modules Ambient free module of rank 2 over the principal ideal domain Integer Ring """ @@ -3902,11 +3975,11 @@ def __eq__(self, other): TESTS:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # indirect doctest # optional - sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic + sage: FM == FG # indirect doctest # optional - sage.symbolic False - sage: FM == loads(dumps(FM)) # optional - sage.symbolic + sage: FM == loads(dumps(FM)) # optional - sage.symbolic True """ if not isinstance(other, BlackBoxConstructionFunctor): @@ -3921,11 +3994,11 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM != FG # indirect doctest # optional - sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic + sage: FM != FG # indirect doctest # optional - sage.symbolic True - sage: FM != loads(dumps(FM)) # optional - sage.symbolic + sage: FM != loads(dumps(FM)) # optional - sage.symbolic False """ return not (self == other) @@ -3984,16 +4057,19 @@ 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'])) - Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 + sage: pushout(Qp(7), Frac(ZZ['x'])) # optional - 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'])) - 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'])) - Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 + sage: pushout(Zp(7), Frac(QQ['x'])) # optional - 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 + Fraction Field of Univariate Polynomial Ring in x + over 7-adic Field with capped relative precision 20 Note that polynomial variable ordering must be unambiguously determined. :: @@ -4001,49 +4077,57 @@ def pushout(R, S): sage: pushout(ZZ['x,y,z'], QQ['w,z,t']) Traceback (most recent call last): ... - CoercionException: ('Ambiguous Base Extension', Multivariate Polynomial Ring in x, y, z over Integer Ring, Multivariate Polynomial Ring in w, z, t over Rational Field) + CoercionException: ('Ambiguous Base Extension', + Multivariate Polynomial Ring in x, y, z over Integer Ring, + Multivariate Polynomial Ring in w, z, t over Rational Field) sage: pushout(ZZ['x,y,z'], QQ['w,x,z,t']) Multivariate Polynomial Ring in w, x, y, z, t over Rational Field Some other examples:: - sage: pushout(Zp(7)['y'], Frac(QQ['t'])['x,y,z']) - 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(Zp(7)['y'], Frac(QQ['t'])['x,y,z']) # optional - 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'])) - 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)) - Full MatrixSpace of 3 by 3 dense matrices over Power Series Ring in x over Integer Ring + 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 + 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 + Full MatrixSpace of 3 by 3 dense matrices + over Power Series Ring in x over Integer Ring sage: pushout(QQ['x,y'], ZZ[['x']]) - Univariate Polynomial Ring in y over Power Series Ring in x over Rational Field + Univariate Polynomial Ring in y + over Power Series Ring in x over Rational Field sage: pushout(Frac(ZZ['x']), QQ[['x']]) Laurent Series Ring in x over Rational Field - A construction with ``coercion_reversed = True`` (currently only + A construction with ``coercion_reversed=True`` (currently only the :class:`SubspaceFunctor` construction) is only applied if it leads to a valid coercion:: - sage: A = ZZ^2 - sage: V = span([[1, 2]], QQ) - sage: P = sage.categories.pushout.pushout(A, V) - sage: P + 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 Vector space of dimension 2 over Rational Field - sage: P.has_coerce_map_from(A) + sage: P.has_coerce_map_from(A) # optional - sage.modules True - sage: V = (QQ^3).span([[1, 2, 3/4]]) - sage: A = ZZ^3 - sage: pushout(A, V) + 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 Vector space of dimension 3 over Rational Field - sage: B = A.span([[0, 0, 2/3]]) - sage: pushout(B, V) + sage: B = A.span([[0, 0, 2/3]]) # optional - sage.modules + sage: pushout(B, V) # optional - sage.modules Vector space of degree 3 and dimension 2 over Rational Field User basis matrix: [1 2 0] [0 0 1] - Some more tests with ``coercion_reversed = True``:: + Some more tests with ``coercion_reversed=True``:: sage: from sage.categories.pushout import ConstructionFunctor sage: class EvenPolynomialRing(type(QQ['x'])): @@ -4082,10 +4166,14 @@ def pushout(R, S): sage: pushout(EvenPolynomialRing(QQ, 'x'), EvenPolynomialRing(RR, 'x')) Even Power Univariate Polynomial Ring in x over Real Field with 53 bits of precision - sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR^2) - 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) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Real Field with 53 bits of precision + sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR^2) # optional - sage.modules + 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 + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x + over Real Field with 53 bits of precision Some more tests related to univariate/multivariate constructions. We consider a generalization of polynomial rings, @@ -4153,7 +4241,8 @@ def pushout(R, S): sage: pushout(GP_ZZ(ZZ), GP_ZZ(QQ)) Generalized Polynomial Ring in X^(Integer Ring) over Rational Field sage: pushout(GP_ZZ(ZZ['t']), GP_ZZ(QQ)) - Generalized Polynomial Ring in X^(Integer Ring) over Univariate Polynomial Ring in t over Rational Field + Generalized Polynomial Ring in X^(Integer Ring) + over Univariate Polynomial Ring in t over Rational Field sage: pushout(GP_ZZ(ZZ['a,b']), GP_ZZ(ZZ['b,c'])) Generalized Polynomial Ring in X^(Integer Ring) over Multivariate Polynomial Ring in a, b, c over Integer Ring @@ -4197,14 +4286,17 @@ def pushout(R, S): ... CoercionException: ('Ambiguous Base Extension', ...) sage: pushout(GP_ZZt(ZZ['a,b']), GP_QQ(ZZ['b,c'])) - Generalized Polynomial Ring in X^(Univariate Polynomial Ring in t over Rational Field) + Generalized Polynomial Ring + in X^(Univariate Polynomial Ring in t over Rational Field) over Multivariate Polynomial Ring in a, b, c over Integer Ring Some tests with Cartesian products:: sage: from sage.sets.cartesian_product import CartesianProduct - sage: A = CartesianProduct((ZZ['x'], QQ['y'], QQ['z']), Sets().CartesianProducts()) - sage: B = CartesianProduct((ZZ['x'], ZZ['y'], ZZ['t']['z']), Sets().CartesianProducts()) + sage: A = CartesianProduct((ZZ['x'], QQ['y'], QQ['z']), + ....: Sets().CartesianProducts()) + sage: B = CartesianProduct((ZZ['x'], ZZ['y'], ZZ['t']['z']), + ....: Sets().CartesianProducts()) sage: A.construction() (The cartesian_product functorial construction, (Univariate Polynomial Ring in x over Integer Ring, @@ -4214,7 +4306,8 @@ def pushout(R, S): The Cartesian product of (Univariate Polynomial Ring in x over Integer Ring, Univariate Polynomial Ring in y over Rational Field, - Univariate Polynomial Ring in z over Univariate Polynomial Ring in t over Rational Field) + Univariate Polynomial Ring in z over + Univariate Polynomial Ring in t over Rational Field) sage: pushout(ZZ, cartesian_product([ZZ, QQ])) Traceback (most recent call last): ... @@ -4226,10 +4319,12 @@ def pushout(R, S): sage: from sage.sets.cartesian_product import CartesianProduct sage: class CartesianProductPoly(CartesianProduct): ....: def __init__(self, polynomial_rings): - ....: sort = sorted(polynomial_rings, key=lambda P: P.variable_name()) + ....: sort = sorted(polynomial_rings, + ....: key=lambda P: P.variable_name()) ....: super().__init__(sort, Sets().CartesianProducts()) ....: def vars(self): - ....: return tuple(P.variable_name() for P in self.cartesian_factors()) + ....: return tuple(P.variable_name() + ....: for P in self.cartesian_factors()) ....: def _pushout_(self, other): ....: if isinstance(other, CartesianProductPoly): ....: s_vars = self.vars() @@ -4263,7 +4358,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'])), # optional - sage.symbolic ....: CartesianProductPoly((ZZ['b,c']['x'], SR['z']))) The Cartesian product of (Univariate Polynomial Ring in x over @@ -4476,14 +4571,16 @@ def pushout_lattice(R, S): EXAMPLES:: sage: from sage.categories.pushout import pushout_lattice - sage: A, B = pushout_lattice(Qp(7), Frac(ZZ['x'])) - sage: A.codomain() - Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 - sage: A.codomain() is B.codomain() + sage: A, B = pushout_lattice(Qp(7), Frac(ZZ['x'])) # optional - sage.rings.padics + sage: A.codomain() # optional - 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 True - sage: A, B = pushout_lattice(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) - sage: B - Identity endomorphism of Full MatrixSpace of 3 by 3 dense matrices over Power Series Ring in x over Integer Ring + sage: A, B = pushout_lattice(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) # optional - sage.modules + sage: B # optional - sage.modules + Identity endomorphism of Full MatrixSpace of 3 by 3 dense matrices + over Power Series Ring in x over Integer Ring AUTHOR: @@ -4652,8 +4749,13 @@ def construction_tower(R): EXAMPLES:: sage: from sage.categories.pushout import construction_tower - sage: construction_tower(MatrixSpace(FractionField(QQ['t']),2)) - [(None, Full MatrixSpace of 2 by 2 dense matrices over Fraction Field of Univariate Polynomial Ring in t over Rational Field), (MatrixFunctor, Fraction Field of Univariate Polynomial Ring in t over Rational Field), (FractionField, Univariate Polynomial Ring in t over Rational Field), (Poly[t], Rational Field), (FractionField, Integer Ring)] + sage: construction_tower(MatrixSpace(FractionField(QQ['t']), 2)) # optional - 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 + of Univariate Polynomial Ring in t over Rational Field), + (FractionField, Univariate Polynomial Ring in t over Rational Field), + (Poly[t], Rational Field), (FractionField, Integer Ring)] """ tower = [(None, R)] @@ -4691,7 +4793,8 @@ def expand_tower(tower): (FractionField, Integer Ring)] sage: expand_tower(construction_tower(QQ['x,y,z'])) [(None, Multivariate Polynomial Ring in x, y, z over Rational Field), - (MPoly[z], Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field), + (MPoly[z], Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field), (MPoly[y], Univariate Polynomial Ring in x over Rational Field), (MPoly[x], Rational Field), (FractionField, Integer Ring)] diff --git a/src/sage/categories/quantum_group_representations.py b/src/sage/categories/quantum_group_representations.py index 125f06c03fa..08219858ca5 100644 --- a/src/sage/categories/quantum_group_representations.py +++ b/src/sage/categories/quantum_group_representations.py @@ -38,7 +38,7 @@ def super_categories(self): sage: from sage.categories.quantum_group_representations import QuantumGroupRepresentations sage: QuantumGroupRepresentations(ZZ['q'].fraction_field()).super_categories() [Category of vector spaces over - Fraction Field of Univariate Polynomial Ring in q over Integer Ring] + Fraction Field of Univariate Polynomial Ring in q over Integer Ring] """ return [Modules(self.base_ring())] @@ -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() + sage: Cat.example() # optional - sage.combinat sage.modules V((2, 1, 0)) """ from sage.algebras.quantum_groups.representations import AdjointRepresentation @@ -79,7 +79,7 @@ def extra_super_categories(self): sage: Cat = QuantumGroupRepresentations(ZZ['q'].fraction_field()) sage: Cat.WithBasis().TensorProducts().extra_super_categories() [Category of quantum group representations with basis over - Fraction Field of Univariate Polynomial Ring in q over Integer Ring] + Fraction Field of Univariate Polynomial Ring in q over Integer Ring] """ return [self.base_category()] @@ -96,34 +96,34 @@ def e_on_basis(self, i, b): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - 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 + 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 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 + sage: v.e(1) # indirect doctest # optional - sage.combinat sage.modules 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 + sage: v.e(2) # indirect doctest # optional - sage.combinat sage.modules 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 + sage: v.e(3) # indirect doctest # optional - sage.combinat sage.modules 0 - sage: v.e(4) # indirect doctest + sage: v.e(4) # indirect doctest # optional - sage.combinat sage.modules 0 """ K_elt = [self._sets[k].K_on_basis(i, elt, -1) for k,elt in enumerate(b)] @@ -146,38 +146,38 @@ def f_on_basis(self, i, b): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - 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 + 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 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 + sage: v.f(0) # indirect doctest # optional - sage.combinat sage.modules ((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 + sage: v.f(1) # indirect doctest # optional - sage.combinat sage.modules 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 + sage: v.f(2) # indirect doctest # optional - sage.combinat sage.modules 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 + sage: v.f(3) # indirect doctest # optional - sage.combinat sage.modules 6*B[[+++, []]] # B[[[1], [0]]] + 4*B[[++-, []]] # B[[]] + 4*B[[++-, []]] # B[[[1], [2]]] @@ -209,22 +209,22 @@ def K_on_basis(self, i, b, power=1): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - 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 + 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 B[[[1]]] # B[[[1, 1], [2]]] + B[[[2]]] # B[[[1, 1], [2]]] + B[[[3]]] # B[[[1, 1], [2]]] - sage: v.K(1) # indirect doctest + sage: v.K(1) # indirect doctest # optional - sage.combinat sage.modules 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 + sage: v.K(2, -1) # indirect doctest # optional - sage.combinat sage.modules 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 +241,24 @@ def tensor(*factors): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - 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) + 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 V((1, 0, 0, 0)) # V((1, 0, 0, 0)) # V((1, 0, 0, 0)) - sage: A = MinusculeRepresentation(R, CA) - sage: V.tensor(A) + sage: A = MinusculeRepresentation(R, CA) # optional - sage.combinat sage.modules + sage: V.tensor(A) # optional - sage.combinat sage.modules V((1, 0, 0, 0)) # V((1, 1, 0, 0)) - sage: B = crystals.Tableaux(['A',2], shape=[1]) - sage: W = MinusculeRepresentation(R, B) - sage: tensor([W,V]) + 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 Traceback (most recent call last): ... ValueError: all factors must be of the same Cartan type - sage: tensor([V,A,W]) + sage: tensor([V,A,W]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: all factors must be of the same Cartan type @@ -279,15 +279,15 @@ def e(self, i): EXAMPLES:: - 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 + 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 2*B[[[1], [2]]] + 2*B[[[1], [3]]] + 3*B[[[2], [3]]] - sage: v.e(1) + sage: v.e(1) # optional - sage.combinat sage.modules ((3*q^4+3*q^2+3)/q^2)*B[[[1], [3]]] - sage: v.e(2) + sage: v.e(2) # optional - sage.combinat sage.modules 2*B[[[1], [2]]] """ F = self.parent() @@ -305,21 +305,21 @@ def f(self, i): EXAMPLES:: - 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 + 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 2*B[[]] + 2*B[[[1], [2]]] + 3*B[[[1], [3]]] - sage: v.f(0) + sage: v.f(0) # optional - sage.combinat sage.modules ((2*q^2+2)/q)*B[[[1], [2]]] - sage: v.f(1) + sage: v.f(1) # optional - sage.combinat sage.modules 3*B[[[2], [3]]] - sage: v.f(2) + sage: v.f(2) # optional - sage.combinat sage.modules 2*B[[[1], [3]]] - sage: v.f(3) + sage: v.f(3) # optional - sage.combinat sage.modules 3*B[[[1], [4]]] - sage: v.f(4) + sage: v.f(4) # optional - sage.combinat sage.modules 3*B[[[1], [-4]]] """ F = self.parent() @@ -338,19 +338,19 @@ def K(self, i, power=1): EXAMPLES:: - 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 + 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 2*B[[]] + 2*B[[[1]]] + 3*B[[[2]]] - sage: v.K(0) + sage: v.K(0) # optional - sage.combinat sage.modules 2*B[[]] + 2/q^2*B[[[1]]] + 3*B[[[2]]] - sage: v.K(1) + sage: v.K(1) # optional - sage.combinat sage.modules 2*B[[]] + 2*q^2*B[[[1]]] + 3/q^2*B[[[2]]] - sage: v.K(1, 2) + sage: v.K(1, 2) # optional - sage.combinat sage.modules 2*B[[]] + 2*q^4*B[[[1]]] + 3/q^4*B[[[2]]] - sage: v.K(1, -1) + sage: v.K(1, -1) # optional - sage.combinat sage.modules 2*B[[]] + 2/q^2*B[[[1]]] + 3*q^2*B[[[2]]] """ F = self.parent() @@ -388,12 +388,12 @@ def cartan_type(self): EXAMPLES:: - 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() + 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 ['C', 2] """ return self._sets[0].cartan_type() @@ -407,18 +407,18 @@ def _test_representation(self, tester=None, **options): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation - sage: C = crystals.Tableaux(['G',2], shape=[1,1]) - sage: R = ZZ['q'].fraction_field() - sage: V = AdjointRepresentation(R, C) - sage: V._test_representation() + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: 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 We verify that ``C`` does not define a minuscule representation:: - sage: M = MinusculeRepresentation(R, C) - sage: M._test_representation() + sage: M = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules + sage: M._test_representation() # optional - 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 +489,11 @@ def cartan_type(self): EXAMPLES:: - 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() + 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 ['C', 4] """ @@ -504,11 +504,11 @@ def index_set(self): EXAMPLES:: - 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() + 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 (1, 2, 3, 4) """ return self.cartan_type().index_set() @@ -519,11 +519,11 @@ def q(self): EXAMPLES:: - 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() + 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 q """ return self._q diff --git a/src/sage/categories/quotient_fields.py b/src/sage/categories/quotient_fields.py index 02780268c8f..c62c79ee11f 100644 --- a/src/sage/categories/quotient_fields.py +++ b/src/sage/categories/quotient_fields.py @@ -75,17 +75,17 @@ def gcd(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) + sage: factor(p) # optional - 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) + sage: factor(q) # optional - sage.libs.pari (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) - sage: gcd(p,q) + sage: gcd(p, q) (x + 1)/(x^7 + x^5 - x^2 - 1) - sage: factor(gcd(p,q)) + sage: factor(gcd(p, q)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(gcd(p,1+x)) + sage: factor(gcd(p, 1 + x)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(gcd(1+x,q)) + sage: factor(gcd(1 + x, q)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 TESTS: @@ -93,22 +93,25 @@ 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') - sage: i = R.1 - sage: gcd(5, 3 + 4*i) + 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 -i - 2 - sage: P. = R[] - sage: gcd(t, i) + sage: P. = R[] # optional - sage.rings.number_field + sage: gcd(t, i) # optional - sage.rings.number_field 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() - 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) + 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 + 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 1 - sage: q.gcd(0) + sage: q.gcd(0) # optional - sage.rings.number_field 1 - sage: (q*0).gcd(0) + sage: (q*0).gcd(0) # optional - sage.rings.number_field 0 """ P = self.parent() @@ -177,15 +180,15 @@ def lcm(self, other): 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) + sage: factor(p) # optional - 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) + sage: factor(q) # optional - sage.libs.pari (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) - sage: factor(lcm(p,q)) + sage: factor(lcm(p, q)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/3) * (x^2 + 1/2) - sage: factor(lcm(p,1+x)) + sage: factor(lcm(p, 1 + x)) # optional - sage.libs.pari (x + 1)^3 * (x^2 + 1/2) - sage: factor(lcm(1+x,q)) + sage: factor(lcm(1 + x, q)) # optional - sage.libs.pari (x + 1) * (x^2 + 1/3) TESTS: @@ -193,20 +196,23 @@ 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') - sage: i = R.1 - sage: P. = R[] - sage: lcm(t, i) + 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 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() - 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) + 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 + 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 1 - sage: q.lcm(0) + sage: q.lcm(0) # optional - sage.rings.number_field 0 - sage: (q*0).lcm(0) + sage: (q*0).lcm(0) # optional - sage.rings.number_field 0 Check that it is possible to take lcm of a rational and an integer @@ -266,11 +272,11 @@ 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) + sage: factor(p) # optional - 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) + sage: factor(q) # optional - 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, s, t = xgcd(p, q) sage: g (x + 1)/(x^7 + x^5 - x^2 - 1) sage: g == s*p + t*q @@ -278,21 +284,21 @@ def xgcd(self, other): An example without a well defined gcd or xgcd on its base ring:: - 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) + 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 1 - sage: x.xgcd(x+1) + sage: x.xgcd(x+1) # optional - sage.rings.number_field (1, 1/x, 0) - sage: zero = F.zero() - sage: zero.gcd(x) + sage: zero = F.zero() # optional - sage.rings.number_field + sage: zero.gcd(x) # optional - sage.rings.number_field 1 - sage: zero.xgcd(x) + sage: zero.xgcd(x) # optional - sage.rings.number_field (1, 0, 1/x) - sage: zero.xgcd(zero) + sage: zero.xgcd(zero) # optional - sage.rings.number_field (0, 0, 0) """ P = self.parent() @@ -340,14 +346,14 @@ def factor(self, *args, **kwds): sage: K. = QQ[] sage: f = (x^3+x)/(x-3) - sage: f.factor() + sage: f.factor() # optional - 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)[] - sage: f = x*y/(x+y) - sage: f.factor() + 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 (x + y)^-1 * y * x """ return (self.numerator().factor(*args, **kwds) / @@ -380,36 +386,38 @@ def partial_fraction_decomposition(self, decompose_powers=True): 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 + sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.libs.pari [3/(t - 3), 1/(t + 1), 2/(t + 2)] - sage: sum(parts) == q + sage: sum(parts) == q # optional - sage.libs.pari True - 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 + 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 + [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 True - sage: q = 2*t / (t + 3)^2 - sage: q.partial_fraction_decomposition() + sage: q = 2*t / (t + 3)^2 # optional - sage.libs.pari + sage: q.partial_fraction_decomposition() # optional - sage.libs.pari (0, [2/(t + 3), -6/(t^2 + 6*t + 9)]) - sage: for p in q.partial_fraction_decomposition()[1]: print(p.factor()) + sage: for p in q.partial_fraction_decomposition()[1]: # optional - sage.libs.pari + ....: print(p.factor()) (2) * (t + 3)^-1 (-6) * (t + 3)^-2 - sage: q.partial_fraction_decomposition(decompose_powers=False) + sage: q.partial_fraction_decomposition(decompose_powers=False) # optional - sage.libs.pari (0, [2*t/(t^2 + 6*t + 9)]) We can decompose over a given algebraic extension:: - sage: R. = QQ[sqrt(2)][] - sage: r = 1/(x^4+1) - sage: r.partial_fraction_decomposition() + sage: R. = QQ[sqrt(2)][] # 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 (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)] - sage: r = 1/(x^4+1) - sage: r.partial_fraction_decomposition() + 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 (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 @@ -417,12 +425,12 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = QQ[] sage: r = 1/(x^4+2) - sage: N = r.denominator().splitting_field('a') - sage: N + sage: N = r.denominator().splitting_field('a') # optional - sage.rings.number_field + sage: N # optional - sage.rings.number_field Number Field in a with defining polynomial x^8 - 8*x^6 + 28*x^4 + 16*x^2 + 36 - sage: R1.=N[] - sage: r1 = 1/(x1^4+2) - sage: r1.partial_fraction_decomposition() + 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 (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), @@ -431,9 +439,9 @@ def partial_fraction_decomposition(self, decompose_powers=True): Or we may work directly over an algebraically closed field:: - sage: R. = QQbar[] - sage: r = 1/(x^4+1) - sage: r.partial_fraction_decomposition() + 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 (0, [(-0.1767766952966369? - 0.1767766952966369?*I)/(x - 0.7071067811865475? - 0.7071067811865475?*I), (-0.1767766952966369? + 0.1767766952966369?*I)/(x - 0.7071067811865475? + 0.7071067811865475?*I), @@ -445,7 +453,7 @@ def partial_fraction_decomposition(self, decompose_powers=True): 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 + sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.rings.number_field [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) (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) @@ -456,23 +464,23 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = ZZ[] sage: q = x^2/(x-1) - sage: q.partial_fraction_decomposition() + sage: q.partial_fraction_decomposition() # optional - sage.libs.pari (x + 1, [1/(x - 1)]) sage: q = x^10/(x-1)^5 - sage: whole, parts = q.partial_fraction_decomposition() - sage: whole + sum(parts) == q + sage: whole, parts = q.partial_fraction_decomposition() # optional - sage.libs.pari + sage: whole + sum(parts) == q # optional - sage.libs.pari True And also over finite fields (see :trac:`6052`, :trac:`9945`):: - sage: R. = GF(2)[] - sage: q = (x+1)/(x^3+x+1) - sage: q.partial_fraction_decomposition() + 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 (0, [(x + 1)/(x^3 + x + 1)]) - sage: R. = GF(11)[] - sage: q = x + 1 + 1/(x+1) + x^2/(x^3 + 2*x + 9) - sage: q.partial_fraction_decomposition() + 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 (x + 1, [1/(x + 1), x^2/(x^3 + 2*x + 9)]) And even the rationals:: diff --git a/src/sage/categories/realizations.py b/src/sage/categories/realizations.py index bbe9a8e8ad4..0207b66a4be 100644 --- a/src/sage/categories/realizations.py +++ b/src/sage/categories/realizations.py @@ -66,19 +66,23 @@ def Realizations(self): The category of realizations of some algebra:: sage: Algebras(QQ).Realizations() - Join of Category of algebras over Rational Field and Category of realizations of unital magmas + Join of Category of algebras over Rational Field + and Category of realizations of unital magmas The category of realizations of a given algebra:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.Realizations() - Category of realizations of The subset algebra of {1, 2, 3} over Rational Field + sage: A.Realizations() # optional - sage.combinat sage.modules + Category of realizations of + The subset algebra of {1, 2, 3} over Rational Field sage: C = GradedHopfAlgebrasWithBasis(QQ).Realizations(); C - Join of Category of graded hopf algebras with basis over Rational Field and Category of realizations of hopf algebras over Rational Field + Join of Category of graded hopf algebras with basis over Rational Field + and Category of realizations of hopf algebras over Rational Field sage: C.super_categories() - [Category of graded hopf algebras with basis over Rational Field, Category of realizations of hopf algebras over Rational Field] + [Category of graded hopf algebras with basis over Rational Field, + Category of realizations of hopf algebras over Rational Field] sage: TestSuite(C).run() @@ -91,7 +95,7 @@ def Realizations(self): Add an optional argument to allow for:: - sage: Realizations(A, category = Blahs()) # todo: not implemented + sage: Realizations(A, category=Blahs()) # todo: not implemented """ if isinstance(self, Category): return RealizationsCategory.category_of(self) @@ -112,7 +116,7 @@ class Category_realization_of_parent(Category_over_base, BindableClass): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat 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 @@ -120,8 +124,9 @@ 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 - Category of realizations of The subset algebra of {1, 2, 3} over Rational Field + sage: C = A.Realizations(); C # optional - sage.combinat sage.modules + Category of realizations of + The subset algebra of {1, 2, 3} over Rational Field as well as the name for that category. """ @@ -130,15 +135,16 @@ def __init__(self, parent_with_realization): TESTS:: sage: from sage.categories.realizations import Category_realization_of_parent - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - 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) + sage: C = A.Realizations(); C # optional - sage.combinat sage.modules + 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 True - sage: C.parent_with_realization + sage: C.parent_with_realization # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: TestSuite(C).run(skip=["_test_category_over_bases"]) + sage: TestSuite(C).run(skip=["_test_category_over_bases"]) # optional - sage.combinat sage.modules .. TODO:: @@ -161,8 +167,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") - sage: MultiplicativeBasesOnPrimitiveElements(Sym)._get_name() + sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # optional - sage.combinat + sage: MultiplicativeBasesOnPrimitiveElements(Sym)._get_name() # optional - sage.combinat 'multiplicative bases on primitive elements' """ import re @@ -179,10 +185,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") - sage: C = MultiplicativeBasesOnPrimitiveElements(Sym); C + sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # optional - sage.combinat + sage: C = MultiplicativeBasesOnPrimitiveElements(Sym); C # optional - sage.combinat Category of multiplicative bases on primitive elements of Sym - sage: C._repr_object_names() + sage: C._repr_object_names() # optional - sage.combinat '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 f5412fe6ab1..afad9e78c22 100644 --- a/src/sage/categories/regular_crystals.py +++ b/src/sage/categories/regular_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Regular Crystals """ @@ -133,21 +134,21 @@ def is_isomorphism(self): EXAMPLES:: - sage: La = RootSystem(['A',2,1]).weight_space(extended=True).fundamental_weights() + sage: A21 = RootSystem(['A',2,1]) + sage: La = A21.weight_space(extended=True).fundamental_weights() sage: B = crystals.LSPaths(La[0]) - sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights() + sage: La = A21.weight_lattice(extended=True).fundamental_weights() sage: C = crystals.GeneralizedYoungWalls(2, La[0]) sage: H = Hom(B, C) sage: from sage.categories.highest_weight_crystals import HighestWeightCrystalMorphism sage: class Psi(HighestWeightCrystalMorphism): ....: def is_strict(self): ....: return True - sage: psi = Psi(H, C.module_generators) - sage: psi + sage: psi = Psi(H, C.module_generators); psi ['A', 2, 1] Crystal morphism: From: The crystal of LS paths of type ['A', 2, 1] and weight Lambda[0] - To: Highest weight crystal of generalized Young walls of Cartan type ['A', 2, 1] - and highest weight Lambda[0] + To: Highest weight crystal of generalized Young walls + of Cartan type ['A', 2, 1] and highest weight Lambda[0] Defn: (Lambda[0],) |--> [] sage: psi.is_isomorphism() True @@ -184,25 +185,28 @@ def demazure_operator(self, element, reduced_word): EXAMPLES:: sage: T = crystals.Tableaux(['A',2], shape=[2,1]) - sage: C = CombinatorialFreeModule(QQ,T) + sage: C = CombinatorialFreeModule(QQ, T) sage: t = T.highest_weight_vector() sage: b = 2*C(t) sage: T.demazure_operator(b,[1,2,1]) - 2*B[[[1, 1], [2]]] + 2*B[[[1, 2], [2]]] + 2*B[[[1, 3], [2]]] + 2*B[[[1, 1], [3]]] - + 2*B[[[1, 2], [3]]] + 2*B[[[1, 3], [3]]] + 2*B[[[2, 2], [3]]] + 2*B[[[2, 3], [3]]] + 2*B[[[1, 1], [2]]] + 2*B[[[1, 2], [2]]] + 2*B[[[1, 3], [2]]] + + 2*B[[[1, 1], [3]]] + 2*B[[[1, 2], [3]]] + 2*B[[[1, 3], [3]]] + + 2*B[[[2, 2], [3]]] + 2*B[[[2, 3], [3]]] The Demazure operator is idempotent:: - sage: T = crystals.Tableaux("A1",shape=[4]) - sage: C = CombinatorialFreeModule(QQ,T) + sage: T = crystals.Tableaux("A1", shape=[4]) + sage: C = CombinatorialFreeModule(QQ, T) sage: b = C(T.module_generators[0]); b B[[[1, 1, 1, 1]]] sage: e = T.demazure_operator(b,[1]); e - B[[[1, 1, 1, 1]]] + B[[[1, 1, 1, 2]]] + B[[[1, 1, 2, 2]]] + B[[[1, 2, 2, 2]]] + B[[[2, 2, 2, 2]]] + B[[[1, 1, 1, 1]]] + B[[[1, 1, 1, 2]]] + B[[[1, 1, 2, 2]]] + + B[[[1, 2, 2, 2]]] + B[[[2, 2, 2, 2]]] sage: e == T.demazure_operator(e,[1]) True - sage: all(T.demazure_operator(T.demazure_operator(C(t),[1]),[1]) == T.demazure_operator(C(t),[1]) for t in T) + sage: all(T.demazure_operator(T.demazure_operator(C(t),[1]),[1]) + ....: == T.demazure_operator(C(t),[1]) for t in T) True """ M = element.parent() diff --git a/src/sage/categories/regular_supercrystals.py b/src/sage/categories/regular_supercrystals.py index 2ed4531c673..9fd6f5c8a83 100644 --- a/src/sage/categories/regular_supercrystals.py +++ b/src/sage/categories/regular_supercrystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Regular Supercrystals """ @@ -107,7 +108,7 @@ def epsilon(self, i): EXAMPLES:: - sage: C = crystals.Tableaux(['A',[1,2]], shape = [2,1]) + sage: C = crystals.Tableaux(['A',[1,2]], shape=[2,1]) sage: c = C.an_element(); c [[-2, -2], [-1]] sage: c.epsilon(2) @@ -132,7 +133,7 @@ def phi(self, i): EXAMPLES:: - sage: C = crystals.Tableaux(['A',[1,2]], shape = [2,1]) + sage: C = crystals.Tableaux(['A',[1,2]], shape=[2,1]) sage: c = C.an_element(); c [[-2, -2], [-1]] sage: c.phi(1) diff --git a/src/sage/categories/rings.py b/src/sage/categories/rings.py index 50dba914250..07ffd95d02b 100644 --- a/src/sage/categories/rings.py +++ b/src/sage/categories/rings.py @@ -67,16 +67,16 @@ def is_injective(self) -> bool: EXAMPLES:: sage: R. = QQ[] - sage: R.hom([x, y^2], R).is_injective() + sage: R.hom([x, y^2], R).is_injective() # optional - sage.libs.singular True - sage: R.hom([x, x^2], R).is_injective() + sage: R.hom([x, x^2], R).is_injective() # optional - sage.libs.singular False - sage: S. = R.quotient(x^3*y) - sage: R.hom([v, u], S).is_injective() + sage: S. = R.quotient(x^3*y) # optional - sage.libs.singular + sage: R.hom([v, u], S).is_injective() # optional - sage.libs.singular False - sage: S.hom([-u, v], S).is_injective() + sage: S.hom([-u, v], S).is_injective() # optional - sage.libs.singular True - sage: S.cover().is_injective() + sage: S.cover().is_injective() # optional - sage.libs.singular False If the domain is a field, the homomorphism is injective:: @@ -102,12 +102,12 @@ def is_injective(self) -> bool: characteristic can not be injective:: sage: R. = ZZ[] - sage: f = R.hom([GF(3)(1)]); f + sage: f = R.hom([GF(3)(1)]); f # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 3 Defn: x |--> 1 - sage: f.is_injective() + sage: f.is_injective() # optional - sage.rings.finite_rings False A morphism whose domain is an order in a number field is injective if @@ -120,18 +120,20 @@ def is_injective(self) -> bool: To: Rational function field in x over Rational Field Defn: Conversion via FractionFieldElement_1poly_field map: From: Integer Ring - To: Fraction Field of Univariate Polynomial Ring in x over Rational Field + To: Fraction Field of Univariate Polynomial Ring in x + over Rational Field then Isomorphism: - From: Fraction Field of Univariate Polynomial Ring in x over Rational Field + From: Fraction Field of Univariate Polynomial Ring in x + over Rational Field To: Rational function field in x over Rational Field sage: f.is_injective() True A coercion to the fraction field is injective:: - sage: R = ZpFM(3) - sage: R.fraction_field().coerce_map_from(R).is_injective() + sage: R = ZpFM(3) # optional - sage.rings.padics + sage: R.fraction_field().coerce_map_from(R).is_injective() # optional - sage.rings.padics True """ @@ -212,23 +214,24 @@ def extend_to_fraction_field(self): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x+1]); f + sage: f = S.hom([x + 1]); f Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 sage: g = f.extend_to_fraction_field(); g - Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field + Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x + over Rational Field Defn: x |--> x + 1 - sage: g(x) + sage: g(x) # optional - sage.libs.singular x + 1 - sage: g(1/x) + sage: g(1/x) # optional - 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) - sage: f.extend_to_fraction_field() + sage: f = GF(5).coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: f.extend_to_fraction_field() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -236,9 +239,10 @@ def extend_to_fraction_field(self): TESTS:: sage: A. = RR[] - sage: phi = A.hom([x+1]) - sage: phi.extend_to_fraction_field() - Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Real Field with 53 bits of precision + sage: phi = A.hom([x + 1]) + sage: phi.extend_to_fraction_field() # optional - 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 """ from sage.rings.morphism import RingHomomorphism_from_fraction_field @@ -332,10 +336,10 @@ def is_zero(self) -> bool: sage: R. = ZZ[] sage: R.quo(1).is_zero() True - sage: R. = GF(101)[] - sage: R.quo(77).is_zero() + sage: R. = GF(101)[] # optional - sage.rings.finite_rings + sage: R.quo(77).is_zero() # optional - sage.rings.finite_rings True - sage: R.quo(x^2+1).is_zero() + sage: R.quo(x^2 + 1).is_zero() # optional - sage.rings.finite_rings False """ return self.one() == self.zero() @@ -350,18 +354,20 @@ def bracket(self, x, y): EXAMPLES:: - 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() - sage: F.bracket(a,b) + sage: F = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: F # optional - 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 = F.algebra_generators() # optional - sage.combinat sage.modules + sage: F.bracket(a, b) # optional - sage.combinat sage.modules 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) + F.bracket(F.bracket(c,a),b) + sage: (F.bracket(F.bracket(a,b), c) + F.bracket(F.bracket(b,c), a) # optional - sage.combinat sage.modules + ....: + F.bracket(F.bracket(c,a), b)) 0 """ return x * y - y * x @@ -386,20 +392,20 @@ def _Hom_(self, Y, category): EXAMPLES:: - sage: H = QQ._Hom_(QQ, category = Rings()); H + sage: H = QQ._Hom_(QQ, category=Rings()); H Set of Homomorphisms from Rational Field to Rational Field sage: H.__class__ TESTS:: - sage: Hom(QQ, QQ, category = Rings()).__class__ + sage: Hom(QQ, QQ, category=Rings()).__class__ - sage: Hom(CyclotomicField(3), QQ, category = Rings()).__class__ + sage: Hom(CyclotomicField(3), QQ, category=Rings()).__class__ # optional - sage.rings.number_field - sage: TestSuite(Hom(QQ, QQ, category = Rings())).run() # indirect doctest + sage: TestSuite(Hom(QQ, QQ, category=Rings())).run() # indirect doctest """ if category is not None and not category.is_subcategory(Rings()): raise TypeError(f"{category} is not a subcategory of Rings()") @@ -439,12 +445,12 @@ 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) - sage: isinstance(MS,Ring) + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: isinstance(MS, Ring) # optional - sage.modules False - sage: MS in Rings() + sage: MS in Rings() # optional - sage.modules True - sage: MS*2 # indirect doctest + sage: MS * 2 # indirect doctest # optional - sage.modules Left Ideal ( [2 0] @@ -455,7 +461,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 + sage: [MS.2] * MS # optional - sage.modules Right Ideal ( [0 0] @@ -501,12 +507,12 @@ def __pow__(self, n): EXAMPLES:: - sage: QQ^5 + sage: QQ^5 # optional - sage.modules Vector space of dimension 5 over Rational Field - sage: Integers(20)^1000 + sage: Integers(20)^1000 # optional - sage.modules Ambient free module of rank 1000 over Ring of integers modulo 20 - sage: QQ^(2,3) + sage: QQ^(2, 3) # optional - sage.modules Full MatrixSpace of 2 by 3 dense matrices over Rational Field """ if isinstance(n, tuple): @@ -531,18 +537,18 @@ def ideal_monoid(self): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2,2) - sage: isinstance(MS,Ring) + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: isinstance(MS, Ring) # optional - sage.modules False - sage: MS in Rings() + sage: MS in Rings() # optional - sage.modules True - sage: MS.ideal_monoid() + sage: MS.ideal_monoid() # optional - sage.modules 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() + sage: MS.ideal_monoid() is MS.ideal_monoid() # optional - sage.modules True """ try: @@ -560,11 +566,11 @@ def characteristic(self): sage: QQ.characteristic() 0 - sage: GF(19).characteristic() + sage: GF(19).characteristic() # optional - sage.rings.finite_rings 19 sage: Integers(8).characteristic() 8 - sage: Zp(5).characteristic() + sage: Zp(5).characteristic() # optional - sage.rings.padics 0 """ from sage.rings.infinity import infinity @@ -619,19 +625,19 @@ def ideal(self, *args, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2,2) - sage: isinstance(MS,Ring) + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: isinstance(MS, Ring) # optional - sage.modules False - sage: MS in Rings() + sage: MS in Rings() # optional - sage.modules True - sage: MS.ideal(2) + sage: MS.ideal(2) # optional - sage.modules 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') + sage: MS.ideal([MS.0, MS.1], side='right') # optional - sage.modules Right Ideal ( [1 0] @@ -733,8 +739,8 @@ def _ideal_class_(self, n=0): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2,2) - sage: MS._ideal_class_() + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: MS._ideal_class_() # optional - sage.modules We do not know of a commutative ring in Sage that does not inherit @@ -782,28 +788,34 @@ 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) - sage: from sage.rings.noncommutative_ideals import Ideal_nc + sage: F. = FreeAlgebra(QQ) # optional - sage.combinat sage.modules + sage: from sage.rings.noncommutative_ideals import Ideal_nc # optional - sage.combinat sage.modules sage: from itertools import product - sage: class PowerIdeal(Ideal_nc): + sage: class PowerIdeal(Ideal_nc): # optional - sage.combinat sage.modules ....: def __init__(self, R, n): ....: self._power = n - ....: Ideal_nc.__init__(self, R, [R.prod(m) for m in product(R.gens(), repeat=n)]) + ....: Ideal_nc.__init__(self, R, [R.prod(m) + ....: for m in product(R.gens(), repeat=n)]) ....: def reduce(self, x): ....: 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) - 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 + ....: 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 + 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 xbar - sage: Q.1 + sage: Q.1 # optional - sage.combinat sage.modules ybar - sage: Q.2 + sage: Q.2 # optional - sage.combinat sage.modules zbar - sage: Q.0*Q.1 + sage: Q.0*Q.1 # optional - sage.combinat sage.modules xbar*ybar - sage: Q.0*Q.1*Q.0 + sage: Q.0*Q.1*Q.0 # optional - sage.combinat sage.modules 0 An example with polynomial rings:: @@ -814,13 +826,14 @@ def quotient(self, I, names=None, **kwds): sage: S.gens() (a,) - sage: R. = PolynomialRing(QQ,2) - 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() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = R.quotient((x^2, y)) # optional - sage.libs.singular + sage: S # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y) + sage: S.gens() # optional - sage.libs.singular (a, 0) - sage: a == b + sage: a == b # optional - sage.libs.singular False """ from sage.rings.quotient_ring import QuotientRing @@ -836,8 +849,8 @@ def quo(self, I, names=None, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2) - sage: I = MS*MS.gens()*MS + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: I = MS * MS.gens() * MS # optional - sage.modules ``MS`` is not an instance of :class:`~sage.rings.ring.Ring`. @@ -845,12 +858,13 @@ def quo(self, I, names=None, **kwds): category of rings. The quotient method is inherited from there:: - sage: isinstance(MS,sage.rings.ring.Ring) + sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules False - sage: isinstance(MS,Rings().parent_class) + sage: isinstance(MS, Rings().parent_class) # optional - sage.modules True - sage: MS.quo(I,names = ['a','b','c','d']) - Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal + sage: MS.quo(I, names=['a','b','c','d']) # optional - sage.modules + Quotient of Full MatrixSpace of 2 by 2 dense matrices + over Rational Field by the ideal ( [1 0] [0 0], @@ -867,13 +881,14 @@ def quo(self, I, names=None, **kwds): A test with a subclass of :class:`~sage.rings.ring.Ring`:: - 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() + 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 + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y) + sage: S.gens() # optional - sage.libs.singular (a, 0) - sage: a == b + sage: a == b # optional - sage.libs.singular False """ return self.quotient(I, names=names, **kwds) @@ -903,19 +918,20 @@ def quotient_ring(self, I, names=None, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2) - sage: I = MS*MS.gens()*MS + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: I = MS * MS.gens() * MS # optional - 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) + sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules False - sage: isinstance(MS,Rings().parent_class) + sage: isinstance(MS, Rings().parent_class) # optional - sage.modules True - sage: MS.quotient_ring(I,names = ['a','b','c','d']) - Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal + sage: MS.quotient_ring(I, names=['a','b','c','d']) # optional - sage.modules + Quotient of Full MatrixSpace of 2 by 2 dense matrices + over Rational Field by the ideal ( [1 0] [0 0], @@ -938,13 +954,14 @@ def quotient_ring(self, I, names=None, **kwds): sage: S.gens() (a,) - 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() + 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 + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y) + sage: S.gens() # optional - sage.libs.singular (a, 0) - sage: a == b + sage: a == b # optional - sage.libs.singular False """ return self.quotient(I, names=names, **kwds) @@ -957,9 +974,9 @@ def __truediv__(self, I): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2) - sage: I = MS*MS.gens()*MS - sage: MS/I + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: I = MS * MS.gens() * MS # optional - sage.modules + sage: MS/I # optional - sage.modules Traceback (most recent call last): ... TypeError: use self.quotient(I) to construct the quotient ring @@ -996,24 +1013,28 @@ 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'] + sage: GF(17)['abc'] # optional - sage.rings.finite_rings Univariate Polynomial Ring in abc over Finite Field of size 17 - sage: GF(17)['a,b,c'] + sage: GF(17)['a,b,c'] # optional - sage.rings.finite_rings Multivariate Polynomial Ring in a, b, c over Finite Field of size 17 - sage: GF(17)['a']['b'] - Univariate Polynomial Ring in b over Univariate Polynomial Ring in a over Finite Field of size 17 + sage: GF(17)['a']['b'] # optional - sage.rings.finite_rings + 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) - sage: Frob = k.frobenius_endomorphism() - sage: k['x', Frob] - Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 + 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 + 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() - sage: R['d', der] - Ore Polynomial Ring in d over Univariate Polynomial Ring in t over Rational Field twisted by d/dt + sage: der = R.derivation() # optional - sage.modules + sage: R['d', der] # optional - sage.modules + Ore Polynomial Ring in d + over Univariate Polynomial Ring in t over Rational Field + twisted by d/dt We can also create power series rings by using double brackets:: @@ -1050,32 +1071,38 @@ def __getitem__(self, arg): :: - sage: QQ[sqrt(2)] # optional - 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: QQ[sqrt(2)] # optional - sage.symbolic sage.rings.number_field + 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 Generic morphism: - From: Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? + From: Number Field in sqrt2 with defining polynomial x^2 - 2 + with sqrt2 = 1.414213562373095? To: Real Lazy Field Defn: sqrt2 -> 1.414213562373095? :: - sage: QQ[sqrt(2), sqrt(3)] # optional - sage.symbolic - Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field + sage: QQ[sqrt(2), sqrt(3)] # optional - sage.symbolic sage.rings.number_field + Number Field in sqrt2 + with defining polynomial x^2 - 2 over its base field and orders in number fields:: - sage: ZZ[I] - Order in Number Field in I0 with defining polynomial x^2 + 1 with I0 = 1*I - sage: ZZ[sqrt(5)] # optional - 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 - Order in Number Field in a with defining polynomial x^4 - 10*x^2 + 1 with a = 3.146264369941973? + sage: ZZ[I] # optional - sage.symbolic sage.rings.number_field + 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 + 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 + 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') - sage: QQ[i].coerce_embedding() + sage: QQi. = QuadraticField(-1, 'i') # optional - sage.symbolic sage.rings.number_field + sage: QQ[i].coerce_embedding() # optional - sage.symbolic sage.rings.number_field Generic morphism: From: Number Field in i with defining polynomial x^2 + 1 with i = 1*I To: Complex Lazy Field @@ -1111,25 +1138,28 @@ 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)] - sage: K - Number Field in a with defining polynomial x^3 - 2 over its base 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() + 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 + 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 + 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 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: QQ[expr].coerce_embedding() is None # optional - sage.symbolic + 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 False - sage: QQ[sqrt(5)].gen() > 0 # optional - sage.symbolic + sage: QQ[sqrt(5)].gen() > 0 # optional - sage.symbolic sage.rings.number_field True - sage: expr = sqrt(2) + I*(cos(pi/4, hold=True) - sqrt(2)/2) # optional - sage.symbolic - sage: QQ[expr].coerce_embedding() # optional - sage.symbolic + 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 Generic morphism: - From: Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095? + From: Number Field in a with defining polynomial x^2 - 2 + with a = 1.414213562373095? To: Real Lazy Field Defn: a -> 1.414213562373095? """ @@ -1251,17 +1281,17 @@ def free_module(self, base=None, basis=None, map=True): EXAMPLES:: sage: R. = QQ[[]] - sage: V, from_V, to_V = R.free_module(R) - sage: v = to_V(1+x); v + sage: V, from_V, to_V = R.free_module(R) # optional - sage.modules + sage: v = to_V(1 + x); v # optional - sage.modules (1 + x) - sage: from_V(v) + sage: from_V(v) # optional - sage.modules 1 + x - sage: W, from_W, to_W = R.free_module(R, basis=(1-x)) - sage: W is V + sage: W, from_W, to_W = R.free_module(R, basis=(1 - x)) # optional - sage.modules + sage: W is V # optional - sage.modules True - sage: w = to_W(1+x); w + sage: w = to_W(1 + x); w # optional - sage.modules (1 - x^2) - sage: from_W(w) + sage: from_W(w) # optional - sage.modules 1 + x + O(x^20) """ if base is None: @@ -1303,12 +1333,12 @@ def is_unit(self) -> bool: EXAMPLES:: - sage: MS = MatrixSpace(ZZ, 2) - sage: MS.one().is_unit() + sage: MS = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: MS.one().is_unit() # optional - sage.modules True - sage: MS.zero().is_unit() + sage: MS.zero().is_unit() # optional - sage.modules False - sage: MS([1,2,3,4]).is_unit() + sage: MS([1,2,3,4]).is_unit() # optional - sage.modules False """ if self.is_one() or (-self).is_one(): @@ -1328,8 +1358,8 @@ def inverse_of_unit(self): EXAMPLES:: sage: R. = ZZ[] - sage: S = R.quo(x^2 + x + 1) - sage: S(1).inverse_of_unit() + sage: S = R.quo(x^2 + x + 1) # optional - sage.libs.pari + sage: S(1).inverse_of_unit() # optional - sage.libs.pari 1 This method fails when the element is not a unit:: @@ -1401,9 +1431,9 @@ def _gen_names(elts): EXAMPLES:: sage: from sage.categories.rings import _gen_names - sage: list(_gen_names([sqrt(5)])) # optional - sage.symbolic + sage: list(_gen_names([sqrt(5)])) # optional - sage.symbolic ['sqrt5'] - sage: list(_gen_names([sqrt(-17), 2^(1/3)])) # optional - sage.symbolic + sage: list(_gen_names([sqrt(-17), 2^(1/3)])) # optional - 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 10e2617e1ab..45bf6ed7305 100644 --- a/src/sage/categories/semigroups.py +++ b/src/sage/categories/semigroups.py @@ -196,30 +196,37 @@ 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 + sage: D4 = DihedralGroup(4); D4 # optional - sage.groups Dihedral group of order 8 as a permutation group - sage: G = D4.cayley_graph() - sage: show(G, color_by_label=True, edge_labels=True) - sage: A5 = AlternatingGroup(5); A5 + 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 Alternating group of order 5!/2 as a permutation group - sage: G = A5.cayley_graph() - sage: G.show3d(color_by_label=True, edge_size=0.01, edge_size2=0.02, vertex_size=0.03) - sage: G.show3d(vertex_size=0.03, 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) # long time (less than a minute) - sage: G.num_edges() + 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 + ....: 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 + ....: 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 120 - sage: w = WeylGroup(['A',3]) - sage: d = w.cayley_graph(); d + sage: w = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: d = w.cayley_graph(); d # optional - sage.combinat sage.groups sage.graphs Digraph on 24 vertices - sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) + sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) # optional - sage.combinat sage.groups sage.graphs sage.plot Alternative generators may be specified:: - sage: G = A5.cayley_graph(generators=[A5.gens()[0]]) - sage: G.num_edges() + sage: G = A5.cayley_graph(generators=[A5.gens()[0]]) # optional - sage.groups sage.graphs + sage: G.num_edges() # optional - sage.groups sage.graphs 60 - 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)]) + sage: g = PermutationGroup([(i + 1, j + 1) # optional - sage.groups sage.graphs + ....: 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 Digraph on 120 vertices If ``elements`` is specified, then only the subgraph @@ -228,57 +235,61 @@ def cayley_graph(self, side="right", simple=False, elements=None, the elements of length at most 3:: sage: M = Monoids().example(); M - An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') - 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) - sage: G.num_verts(), G.num_edges() + An example of a monoid: + the free monoid generated by ('a', 'b', 'c', 'd') + sage: elements = [M.prod(w) # optional - sage.combinat + ....: 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 (85, 84) - sage: G.show3d(color_by_label=True, edge_size=0.001, vertex_size=0.01) + sage: G.show3d(color_by_label=True, edge_size=0.001, vertex_size=0.01) # optional - sage.combinat sage.graphs 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) - sage: g.vertices(sort=True) + 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 ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [('a', 'ab', None), ('b', 'ba', None)] :: - sage: g = S.cayley_graph(side="left", simple=True) - sage: g.vertices(sort=True) + sage: g = S.cayley_graph(side="left", simple=True) # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [('a', 'ba', None), ('ab', 'ba', None), ('b', 'ab', None), ('ba', 'ab', None)] :: - sage: g = S.cayley_graph(side="twosided", simple=True) - sage: g.vertices(sort=True) + sage: g = S.cayley_graph(side="twosided", simple=True) # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - 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") - sage: g.vertices(sort=True) + sage: g = S.cayley_graph(side="twosided") # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - 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(); s.vertices(sort=False) + sage: s1 = SymmetricGroup(1); s = s1.cayley_graph() # optional - sage.groups sage.graphs + sage: s.vertices(sort=False) # optional - sage.groups sage.graphs [()] TESTS:: - sage: SymmetricGroup(2).cayley_graph(side="both") + sage: SymmetricGroup(2).cayley_graph(side="both") # optional - sage.groups sage.graphs Traceback (most recent call last): ... ValueError: option 'side' must be 'left', 'right' or 'twosided' @@ -375,51 +386,52 @@ def subsemigroup(self, generators, one=None, category=None): EXAMPLES:: sage: R = IntegerModRing(15) - sage: M = R.subsemigroup([R(3),R(5)]); M + sage: M = R.subsemigroup([R(3), R(5)]); M # optional - sage.groups A subsemigroup of (Ring of integers modulo 15) with 2 generators - sage: M.list() + sage: M.list() # optional - sage.groups [3, 5, 9, 0, 10, 12, 6] By default, `M` is just in the category of subsemigroups:: - sage: M in Semigroups().Subobjects() + sage: M in Semigroups().Subobjects() # optional - sage.groups 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)], + sage: M = R.subsemigroup([R(-1)], # optional - sage.groups ....: category=Monoids().Finite().Subobjects() & Groups()); M A submonoid of (Ring of integers modulo 15) with 1 generators - sage: M.list() + sage: M.list() # optional - sage.groups [1, 14] - sage: M.one() + sage: M.one() # optional - sage.groups 1 - In the following example `M` is a group; however its unit + 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)], + sage: M = R.subsemigroup([R(5)], # optional - sage.groups ....: 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 + ValueError: For a monoid which is just a subsemigroup, + the unit should be specified - sage: M = R.subsemigroup([R(5)], one=R(10), + sage: M = R.subsemigroup([R(5)], one=R(10), # optional - sage.groups ....: category=Semigroups().Finite().Subobjects() & Groups()); M A subsemigroup of (Ring of integers modulo 15) with 1 generators - sage: M in Groups() + sage: M in Groups() # optional - sage.groups True - sage: M.list() + sage: M.list() # optional - sage.groups [10, 5] - sage: M.one() + sage: M.one() # optional - sage.groups 10 TESTS:: - sage: TestSuite(M).run() + sage: TestSuite(M).run() # optional - sage.groups Failure in _test_inverse: Traceback (most recent call last): ... @@ -449,8 +461,8 @@ def trivial_representation(self, base_ring=None, side="twosided"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: G.trivial_representation() + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: G.trivial_representation() # optional - sage.groups Trivial representation of Dihedral group of order 8 as a permutation group over Integer Ring """ @@ -469,8 +481,8 @@ def regular_representation(self, base_ring=None, side="left"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: G.regular_representation() + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: G.regular_representation() # optional - sage.groups Left Regular Representation of Dihedral group of order 8 as a permutation group over Integer Ring """ @@ -880,7 +892,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() + sage: M.algebra(ZZ).algebra_generators() # optional - sage.modules Family (B['a'], B['b'], B['c'], B['d']) """ return self.basis().keys().semigroup_generators().map(self.monomial) @@ -895,12 +907,12 @@ def gens(self): EXAMPLES:: - sage: a, b = SL2Z.algebra(ZZ).gens(); a, b + sage: a, b = SL2Z.algebra(ZZ).gens(); a, b # optional - sage.groups sage.modules ([ 0 -1] [ 1 0], [1 1] [0 1]) - sage: 2*a + b + sage: 2*a + b # optional - sage.groups sage.modules 2*[ 0 -1] [ 1 0] + @@ -915,9 +927,9 @@ def ngens(self): EXAMPLES:: - sage: SL2Z.algebra(ZZ).ngens() + sage: SL2Z.algebra(ZZ).ngens() # optional - sage.groups sage.modules 2 - sage: DihedralGroup(4).algebra(RR).ngens() + sage: DihedralGroup(4).algebra(RR).ngens() # optional - sage.groups sage.modules 2 """ return self.basis().keys().ngens() @@ -928,8 +940,8 @@ def gen(self, i=0): EXAMPLES:: - sage: A = GL(3, GF(7)).algebra(ZZ) - sage: A.gen(0) + 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 [3 0 0] [0 1 0] [0 0 1] @@ -948,10 +960,11 @@ def product_on_basis(self, g1, g2): EXAMPLES:: 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) - sage: a,b,c,d = A.algebra_generators() - sage: a * b + b * d * c * d + 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 B['ab'] + B['bdc'] """ return self.monomial(g1 * g2) @@ -966,10 +979,10 @@ def trivial_representation(self, side="twosided"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: A = G.algebra(QQ) - sage: V = A.trivial_representation() - sage: V == G.trivial_representation(QQ) + 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 True """ S = self.basis().keys() @@ -986,10 +999,10 @@ def regular_representation(self, side="left"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: A = G.algebra(QQ) - sage: V = A.regular_representation() - sage: V == G.regular_representation(QQ) + 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 True """ S = self.basis().keys() diff --git a/src/sage/categories/semisimple_algebras.py b/src/sage/categories/semisimple_algebras.py index be7a581c798..9be6bb8d571 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 + sage: DihedralGroup(5).algebra(QQ) in SemisimpleAlgebras # optional - sage.groups True Unless the characteristic of the field divides the order of the group:: - sage: DihedralGroup(5).algebra(IntegerModRing(5)) in SemisimpleAlgebras + sage: DihedralGroup(5).algebra(IntegerModRing(5)) in SemisimpleAlgebras # optional - sage.groups False - sage: DihedralGroup(5).algebra(IntegerModRing(7)) in SemisimpleAlgebras + sage: DihedralGroup(5).algebra(IntegerModRing(7)) in SemisimpleAlgebras # optional - sage.groups True .. SEEALSO:: :wikipedia:`Semisimple_algebra` @@ -96,13 +96,13 @@ def radical_basis(self, **keywords): EXAMPLES:: - sage: A = SymmetricGroup(4).algebra(QQ) - sage: A.radical_basis() + sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups + sage: A.radical_basis() # optional - sage.groups () TESTS:: - sage: A.radical_basis.__module__ + sage: A.radical_basis.__module__ # optional - 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 bc3c55e9029..069ebc5337c 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) + sage: TestSuite(P).run(verbose=True) # optional - 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) + sage: P = Poset((divisors(12), attrcall("divides")), facade=True) # optional - sage.graphs sage.combinat 2. as integers, modified to be aware that their parent is `P`:: - sage: Q = Poset((divisors(12), attrcall("divides")), facade=False) + sage: Q = Poset((divisors(12), attrcall("divides")), facade=False) # optional - sage.graphs sage.combinat 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") - sage: P.lt(2,3) + sage: P = Posets().example("facade") # optional - sage.graphs sage.combinat + sage: P.lt(2,3) # optional - sage.graphs sage.combinat False On the other hand, with option 2. and once constructed, the elements know unambiguously how to compare themselves:: - sage: Q(2) < Q(3) + sage: Q(2) < Q(3) # optional - sage.graphs sage.combinat False - sage: Q(2) < Q(6) + sage: Q(2) < Q(6) # optional - sage.graphs sage.combinat 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) + sage: P(2) < P(3) # optional - sage.graphs sage.combinat True In short `P` being a facade parent is one of the programmatic @@ -970,17 +970,19 @@ def _element_constructor_(self): sage: S(17) # indirect doctest 17 - sage: A = FreeModule(QQ, 3) - sage: A.element_class + sage: A = FreeModule(QQ, 3) # optional - sage.modules + sage: A.element_class # optional - sage.modules - sage: A._element_constructor_ - + sage: A._element_constructor_ # optional - sage.modules + - sage: B = SymmetricGroup(3).algebra(ZZ) - sage: B.element_class + sage: B = SymmetricGroup(3).algebra(ZZ) # optional - sage.groups sage.modules + sage: B.element_class # optional - sage.groups sage.modules <...SymmetricGroupAlgebra_n_with_category.element_class'> - sage: B._element_constructor_ - + sage: B._element_constructor_ # optional - sage.groups sage.modules + """ if hasattr(self, "element_class"): return self._element_constructor_from_element_class @@ -1190,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() + sage: P._test_elements_eq_reflexive() # optional - 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() + sage: P._test_elements_eq_reflexive() # optional - sage.libs.pari Traceback (most recent call last): ... AssertionError: 47 != 47 @@ -1226,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() + sage: P._test_elements_eq_symmetric() # optional - sage.libs.pari sage: eq = P.element_class.__eq__ sage: def non_sym_eq(x, y): @@ -1234,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() + sage: P._test_elements_eq_symmetric() # optional - sage.libs.pari Traceback (most recent call last): ... AssertionError: non symmetric equality: 47 == 53 but 53 != 47 @@ -1267,9 +1269,9 @@ def _test_elements_eq_transitive(self, **options): We test a non transitive equality:: - sage: R = Zp(3) - sage: test = raw_getattr(Sets().ParentMethods, "_test_elements_eq_transitive") - sage: test(R, elements=[R(3,2),R(3,1),R(0)]) + 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 Traceback (most recent call last): ... AssertionError: non transitive equality: @@ -1316,12 +1318,12 @@ def _test_elements_neq(self, **options): We try a broken inequality:: sage: P = Sets().example("wrapper") - sage: P._test_elements_neq() + sage: P._test_elements_neq() # optional - 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() + sage: P._test_elements_neq() # optional - sage.libs.pari Traceback (most recent call last): ... AssertionError: __eq__ and __ne__ inconsistency: @@ -1560,20 +1562,21 @@ def cartesian_product(*parents, **kwargs): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example(); A.rename("A") - sage: A.cartesian_product(A,A) + sage: A = C.example(); A.rename("A") # optional - sage.combinat sage.modules + sage: A.cartesian_product(A, A) # optional - sage.combinat sage.modules A (+) A (+) A - 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: ZZ.cartesian_product(GF(2), FiniteEnumeratedSet([1,2,3])) # optional - sage.rings.finite_rings + The Cartesian product of (Integer Ring, + Finite Field of size 2, {1, 2, 3}) - sage: C = ZZ.cartesian_product(A); C + sage: C = ZZ.cartesian_product(A); C # optional - sage.combinat sage.modules The Cartesian product of (Integer Ring, A) TESTS:: - sage: type(C) + sage: type(C) # optional - sage.combinat sage.modules - sage: C.category() + sage: C.category() # optional - sage.combinat sage.modules Join of Category of rings and ... and Category of Cartesian products of commutative additive groups @@ -1626,21 +1629,21 @@ 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 - Dihedral group of order 8 as a permutation group - sage: A = S.algebra(QQ); A + sage: S = DihedralGroup(4); S # optional - sage.groups + Dihedral group of order 8 as a permutation group + sage: A = S.algebra(QQ); A # optional - sage.groups sage.modules Algebra of Dihedral group of order 8 as a permutation group - over Rational Field - sage: A.category() + over Rational Field + sage: A.category() # optional - sage.groups sage.modules Category of finite group algebras over Rational Field - sage: a = A.an_element(); a + sage: a = A.an_element(); a # optional - sage.groups sage.modules () + (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 + sage: a * a # optional - 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) @@ -1648,11 +1651,13 @@ def algebra(self, base_ring, category=None, **kwds): monoid algebra `KS`:: 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 - Algebra of An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') - over Rational Field - sage: A.category() + An example of a monoid: + the free monoid generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(QQ); A # optional - 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 Category of monoid algebras over Rational Field Similarly, we can construct algebras for additive magmas, @@ -1662,17 +1667,17 @@ def algebra(self, base_ring, category=None, **kwds): here we build the algebra of the additive group `GF_3`:: sage: from sage.categories.additive_groups import AdditiveGroups - sage: S = GF(7) - sage: A = S.algebra(QQ, category=AdditiveGroups()); A + sage: S = GF(7) # optional - sage.rings.finite_rings + sage: A = S.algebra(QQ, category=AdditiveGroups()); A # optional - sage.rings.finite_rings sage.modules Algebra of Finite Field of size 7 over Rational Field - sage: A.category() + sage: A.category() # optional - sage.rings.finite_rings sage.modules Category of finite dimensional additive group algebras over Rational Field - sage: a = A(S(1)) - sage: a + sage: a = A(S(1)) # optional - sage.rings.finite_rings sage.modules + sage: a # optional - sage.rings.finite_rings sage.modules 1 - sage: 1 + a * a * a + sage: 1 + a * a * a # optional - sage.rings.finite_rings sage.modules 0 + 3 Note that the ``category`` keyword needs to be fed with @@ -1717,29 +1722,29 @@ def _sympy_(self): sage: F = FiniteEnumeratedSets().example(); F An example of a finite enumerated set: {1,2,3} - sage: sF = F._sympy_(); sF + sage: sF = F._sympy_(); sF # optional - sympy SageSet(An example of a finite enumerated set: {1,2,3}) - sage: sF.is_finite_set + sage: sF.is_finite_set # optional - sympy True - sage: bool(sF) + sage: bool(sF) # optional - sympy True - sage: len(sF) + sage: len(sF) # optional - sympy 3 - sage: list(sF) + sage: list(sF) # optional - sympy [1, 2, 3] - sage: from sympy import FiniteSet - sage: FiniteSet.fromiter(sF) # random - this output format is sympy >= 1.9 + sage: from sympy import FiniteSet # optional - sympy + sage: FiniteSet.fromiter(sF) # random - this output is sympy >= 1.9 # optional - sympy FiniteSet(1, 2, 3) - sage: RR._sympy_().is_finite_set + sage: RR._sympy_().is_finite_set # optional - sympy False sage: F = Family([1, 2]) sage: F is Family([1, 2]) False - sage: sF = F._sympy_(); sF + sage: sF = F._sympy_(); sF # optional - sympy SageSet(Family (1, 2)) - sage: sF._sage_() is F + sage: sF._sage_() is F # optional - sympy True """ from sage.interfaces.sympy_wrapper import SageSet @@ -1764,9 +1769,9 @@ def cartesian_product(*elements): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example() - sage: (a,b,c) = A.algebra_generators() - sage: a.cartesian_product(b, c) + 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 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? @@ -1800,22 +1805,22 @@ def __invert__(self): We now try to inverse a couple of morphisms defined by a matrix:: - sage: H = End(QQ^2) - sage: phi = H(matrix([[1,1],[0,1]])); phi + sage: H = End(QQ^2) # optional - sage.modules + sage: phi = H(matrix([[1,1], [0,1]])); phi # optional - 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 + sage: ~phi # optional - 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]])) - sage: ~phi + sage: phi = H(matrix([[1,1], [1,1]])) # optional - sage.modules + sage: ~phi # optional - sage.modules Traceback (most recent call last): ... ZeroDivisionError: matrix morphism not invertible @@ -1832,11 +1837,11 @@ def is_injective(self): EXAMPLES:: - sage: f = ZZ.hom(GF(3)); f + sage: f = ZZ.hom(GF(3)); f # optional - sage.rings.finite_rings Natural morphism: From: Integer Ring To: Finite Field of size 3 - sage: f.is_injective() + sage: f.is_injective() # optional - sage.rings.finite_rings False """ if self.domain().cardinality() <= 1: @@ -1851,11 +1856,11 @@ def image(self, domain_subset=None): EXAMPLES:: - sage: P = Partitions(6) - sage: H = Hom(P, ZZ) - sage: f = H(ZZ.sum) - sage: X = f.image() - sage: list(X) + 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 [6] """ D = self.domain() @@ -2006,7 +2011,8 @@ def lift(self, x): sage: S = Semigroups().Subquotients().example() sage: s = S.an_element() sage: s, s.parent() - (42, An example of a (sub)quotient semigroup: a quotient of the left zero semigroup) + (42, An example of a (sub)quotient semigroup: + a quotient of the left zero semigroup) sage: S.lift(s), S.lift(s).parent() (42, An example of a semigroup: the left zero semigroup) sage: s.lift(), s.lift().parent() @@ -2041,7 +2047,8 @@ def retract(self, x): sage: s, s.parent() (42, An example of a semigroup: the left zero semigroup) sage: S.retract(s), S.retract(s).parent() - (42, An example of a (sub)quotient semigroup: a quotient of the left zero semigroup) + (42, An example of a (sub)quotient semigroup: + a quotient of the left zero semigroup) """ class ElementMethods: @@ -2055,7 +2062,8 @@ def lift(self): sage: S = Semigroups().Subquotients().example() sage: s = S.an_element() sage: s, s.parent() - (42, An example of a (sub)quotient semigroup: a quotient of the left zero semigroup) + (42, An example of a (sub)quotient semigroup: + a quotient of the left zero semigroup) sage: S.lift(s), S.lift(s).parent() (42, An example of a semigroup: the left zero semigroup) sage: s.lift(), s.lift().parent() @@ -2132,7 +2140,7 @@ def _repr_(self): EXAMPLES:: sage: from sage.categories.examples.semigroups import IncompleteSubquotientSemigroup - sage: S = IncompleteSubquotientSemigroup(category = Semigroups().Subobjects()) + sage: S = IncompleteSubquotientSemigroup(category=Semigroups().Subobjects()) sage: S._repr_() 'A subobject of An example of a semigroup: the left zero semigroup' """ @@ -2231,7 +2239,7 @@ def __iter__(self): Sets are intrinsically unordered:: - sage: for x,y in cartesian_product([Set([1,2]), Set(['a','b'])]): # random + sage: for x,y in cartesian_product([Set([1,2]), Set(['a','b'])]): # random ....: print((x, y)) (1, 'b') (1, 'a') @@ -2251,18 +2259,18 @@ def __iter__(self): sage: C.__iter__.__module__ 'sage.categories.sets_cat' - sage: F22 = GF(2).cartesian_product(GF(2)) - sage: list(F22) + sage: F22 = GF(2).cartesian_product(GF(2)) # optional - sage.rings.finite_rings + sage: list(F22) # optional - sage.rings.finite_rings [(0, 0), (0, 1), (1, 0), (1, 1)] - sage: C = cartesian_product([Permutations(10)]*4) - sage: it = iter(C) - sage: next(it) + sage: C = cartesian_product([Permutations(10)]*4) # optional - sage.combinat + sage: it = iter(C) # optional - sage.combinat + sage: next(it) # optional - sage.combinat ([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) + sage: next(it) # optional - sage.combinat ([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], @@ -2271,8 +2279,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)])) - sage: [next(it) for _ in range(10)] + 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 [(0, 0), (0, 1), (1, 0), (1, 1), (-1, 0), (-1, 1), @@ -2292,8 +2300,8 @@ def __iter__(self): An example with the first factor finite, the second infinite:: - sage: it = iter(cartesian_product([GF(2), ZZ])) - sage: [next(it) for _ in range(11)] + 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 [(0, 0), (1, 0), (0, 1), (1, 1), (0, -1), @@ -2378,8 +2386,8 @@ def is_finite(self): EXAMPLES:: sage: E = FiniteEnumeratedSet([1,2,3]) - sage: C = cartesian_product([E, SymmetricGroup(4)]) - sage: C.is_finite() + sage: C = cartesian_product([E, SymmetricGroup(4)]) # optional - sage.groups + sage: C.is_finite() # optional - sage.groups True sage: cartesian_product([ZZ,ZZ]).is_finite() @@ -2406,8 +2414,8 @@ def cardinality(self): EXAMPLES:: sage: E = FiniteEnumeratedSet([1,2,3]) - sage: C = cartesian_product([E,SymmetricGroup(4)]) - sage: C.cardinality() + sage: C = cartesian_product([E, SymmetricGroup(4)]) # optional - sage.groups + sage: C.cardinality() # optional - sage.groups 72 sage: E = FiniteEnumeratedSet([]) @@ -2419,9 +2427,9 @@ def cardinality(self): sage: C.cardinality() +Infinity - sage: cartesian_product([GF(5), Permutations(10)]).cardinality() + sage: cartesian_product([GF(5), Permutations(10)]).cardinality() # optional - sage.rings.finite_rings sage.combinat 18144000 - sage: cartesian_product([GF(71)]*20).cardinality() == 71**20 + sage: cartesian_product([GF(71)]*20).cardinality() == 71**20 # optional - sage.rings.finite_rings True """ f = self.cartesian_factors() @@ -2452,8 +2460,8 @@ def random_element(self, *args): EXAMPLES:: - sage: C = cartesian_product([Permutations(10)]*5) - sage: C.random_element() # random + sage: C = cartesian_product([Permutations(10)]*5) # optional - sage.combinat + sage: C.random_element() # random # optional - sage.combinat ([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], @@ -2562,9 +2570,9 @@ def _sympy_(self): EXAMPLES:: sage: ZZ3 = cartesian_product([ZZ, ZZ, ZZ]) - sage: sZZ3 = ZZ3._sympy_(); sZZ3 + sage: sZZ3 = ZZ3._sympy_(); sZZ3 # optional - sympy ProductSet(Integers, Integers, Integers) - sage: (1, 2, 3) in sZZ3 + sage: (1, 2, 3) in sZZ3 # optional - sympy True """ from sympy import ProductSet @@ -2585,13 +2593,14 @@ def cartesian_projection(self, i): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.__custom_name = "F" - sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.__custom_name = "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) + 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 + ....: + 3 * S.monomial((1,6))) + sage: x.cartesian_projection(0) # optional - sage.modules B[4] + 2*B[5] - sage: x.cartesian_projection(1) + sage: x.cartesian_projection(1) # optional - sage.modules 3*B[6] """ return self.parent().cartesian_projection(i)(self) @@ -2602,18 +2611,20 @@ def cartesian_factors(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.__custom_name = "F" - sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.__custom_name = "G" - sage: H = CombinatorialFreeModule(ZZ, [4,7]); H.__custom_name = "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() + 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 + ....: + 3 * S.monomial((1,6)) + 4 * S.monomial((2,4)) + ....: + 5 * S.monomial((2,7))) + sage: x.cartesian_factors() # optional - sage.modules (B[4] + 2*B[5], 3*B[6], 4*B[4] + 5*B[7]) - sage: [s.parent() for s in x.cartesian_factors()] + sage: [s.parent() for s in x.cartesian_factors()] # optional - sage.modules [F, G, H] - sage: S.zero().cartesian_factors() + sage: S.zero().cartesian_factors() # optional - sage.modules (0, 0, 0) - sage: [s.parent() for s in S.zero().cartesian_factors()] + sage: [s.parent() for s in S.zero().cartesian_factors()] # optional - sage.modules [F, G, H] """ # TODO: optimize @@ -2633,7 +2644,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() + sage: Sets().example().algebra(ZZ).categories() # optional - sage.groups sage.modules [Category of set algebras over Integer Ring, Category of modules with basis over Integer Ring, ... @@ -2650,20 +2661,20 @@ def construction(self): EXAMPLES:: - sage: A = GroupAlgebra(KleinFourGroup(), QQ) - sage: F, arg = A.construction(); F, arg + sage: A = GroupAlgebra(KleinFourGroup(), QQ) # optional - sage.groups sage.modules + sage: F, arg = A.construction(); F, arg # optional - sage.groups sage.modules (GroupAlgebraFunctor, Rational Field) - sage: F(arg) is A + sage: F(arg) is A # optional - sage.groups sage.modules True This also works for structures such as monoid algebras (see :trac:`27937`):: - sage: A = FreeAbelianMonoid('x,y').algebra(QQ) - sage: F, arg = A.construction(); F, arg + sage: A = FreeAbelianMonoid('x,y').algebra(QQ) # optional - sage.groups sage.modules + sage: F, arg = A.construction(); F, arg # optional - sage.groups sage.modules (The algebra functorial construction, Free abelian monoid on 2 generators (x, y)) - sage: F(arg) is A + sage: F(arg) is A # optional - sage.groups sage.modules True """ from sage.categories.algebra_functor import ( @@ -2681,14 +2692,14 @@ def _repr_(self): EXAMPLES:: - sage: A = Groups().example().algebra(QQ); A + sage: A = Groups().example().algebra(QQ); A # optional - sage.groups sage.modules Algebra of General Linear Group of degree 4 over Rational Field over Rational Field - sage: A._name = "foo" - sage: A + sage: A._name = "foo" # optional - sage.groups sage.modules + sage: A # optional - sage.groups sage.modules foo over Rational Field - sage: A = KleinFourGroup().algebra(ZZ) - sage: A + sage: A = KleinFourGroup().algebra(ZZ) # optional - sage.groups sage.modules + sage: A # optional - sage.groups sage.modules Algebra of The Klein 4 group of order 4, as a permutation group over Integer Ring """ @@ -2720,10 +2731,10 @@ def example(self, base_ring=None, set=None): EXAMPLES:: - sage: Sets().WithRealizations().example() + sage: Sets().WithRealizations().example() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: Sets().WithRealizations().example(ZZ, Set([1,2])) + sage: Sets().WithRealizations().example(ZZ, Set([1,2])) # optional - sage.combinat sage.modules The subset algebra of {1, 2} over Integer Ring """ from sage.rings.rational_field import QQ @@ -2749,8 +2760,8 @@ def _test_with_realizations(self, **options): EXAMPLES:: - sage: A = Sets().WithRealizations().example() - sage: A._test_with_realizations() + sage: A = Sets().WithRealizations().example() # optional - sage.combinat sage.modules + sage: A._test_with_realizations() # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. @@ -2780,13 +2791,15 @@ def _register_realization(self, realization): """ EXAMPLES:: - 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): + sage: A = Sets().WithRealizations().example(QQ['x']); A # optional - sage.combinat sage.modules + 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 ....: pass - 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 + 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 + ....: category=category) + sage: R in A.realizations() # indirect doctest # optional - sage.combinat sage.modules True Note: the test above uses ``QQ[x]`` to not interfer @@ -2814,82 +2827,102 @@ 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 + sage: S = SymmetricFunctions(ZZ); S # optional - sage.combinat Symmetric Functions over Integer Ring - sage: s = S.s(); s + sage: s = S.s(); s # optional - sage.combinat Symmetric Functions over Integer Ring in the Schur basis - sage: e = S.e(); e + sage: e = S.e(); e # optional - sage.combinat Symmetric Functions over Integer Ring in the elementary basis This method automates the process:: - sage: S.inject_shorthands() - Defining e as shorthand for Symmetric Functions over Integer Ring in the elementary basis - Defining f as shorthand for Symmetric Functions over Integer Ring in the forgotten basis - Defining h as shorthand for Symmetric Functions over Integer Ring in the homogeneous basis - Defining m as shorthand for Symmetric Functions over Integer Ring in the monomial basis - Defining p as shorthand for 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] - 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 + sage: S.inject_shorthands() # optional - sage.combinat + Defining e as shorthand for + Symmetric Functions over Integer Ring in the elementary basis + Defining f as shorthand for + Symmetric Functions over Integer Ring in the forgotten basis + Defining h as shorthand for + Symmetric Functions over Integer Ring in the homogeneous basis + Defining m as shorthand for + Symmetric Functions over Integer Ring in the monomial basis + Defining p as shorthand for + 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 + 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 Symmetric Functions over Integer Ring in the elementary basis - sage: p + sage: p # optional - sage.combinat Symmetric Functions over Integer Ring in the powersum basis - sage: s + sage: s # optional - sage.combinat 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") - Defining e as shorthand for Symmetric Functions over Integer Ring in the elementary basis - Defining f as shorthand for Symmetric Functions over Integer Ring in the forgotten basis - Defining h as shorthand for Symmetric Functions over Integer Ring in the homogeneous basis - Defining ht as shorthand for Symmetric Functions over Integer Ring in the induced trivial symmetric group character basis - Defining m as shorthand for Symmetric Functions over Integer Ring in the monomial basis - Defining o as shorthand for Symmetric Functions over Integer Ring in the orthogonal basis - Defining p as shorthand for Symmetric Functions over Integer Ring in the powersum basis - Defining s as shorthand for Symmetric Functions over Integer Ring in the Schur basis - Defining sp as shorthand for Symmetric Functions over Integer Ring in the symplectic basis - Defining st as shorthand for Symmetric Functions over Integer Ring in the irreducible symmetric group character basis - Defining w as shorthand for Symmetric Functions over Integer Ring in the Witt basis + sage: S.inject_shorthands("all") # optional - sage.combinat + Defining e as shorthand for + Symmetric Functions over Integer Ring in the elementary basis + Defining f as shorthand for + Symmetric Functions over Integer Ring in the forgotten basis + Defining h as shorthand for + Symmetric Functions over Integer Ring in the homogeneous basis + Defining ht as shorthand for + Symmetric Functions over Integer Ring in the + induced trivial symmetric group character basis + Defining m as shorthand for + Symmetric Functions over Integer Ring in the monomial basis + Defining o as shorthand for + Symmetric Functions over Integer Ring in the orthogonal basis + Defining p as shorthand for + Symmetric Functions over Integer Ring in the powersum basis + Defining s as shorthand for + Symmetric Functions over Integer Ring in the Schur basis + Defining sp as shorthand for + Symmetric Functions over Integer Ring in the symplectic basis + Defining st as shorthand for + Symmetric Functions over Integer Ring in the + irreducible symmetric group character basis + Defining w as shorthand for + Symmetric Functions over Integer Ring in the Witt basis The messages can be silenced by setting ``verbose=False``:: - sage: Q = QuasiSymmetricFunctions(ZZ) - sage: Q.inject_shorthands(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 + sage: F[1,2,1] + 5*M[1,3] + F[2]^2 # optional - sage.combinat 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 + sage: F # optional - sage.combinat Quasisymmetric functions over the Integer Ring in the Fundamental basis - sage: M + sage: M # optional - sage.combinat Quasisymmetric functions over the Integer Ring in the Monomial basis One can also just import a subset of the shorthands:: - sage: SQ = SymmetricFunctions(QQ) - sage: SQ.inject_shorthands(['p', 's'], verbose=False) - sage: p + sage: SQ = SymmetricFunctions(QQ) # optional - sage.combinat + sage: SQ.inject_shorthands(['p', 's'], verbose=False) # optional - sage.combinat + sage: p # optional - sage.combinat Symmetric Functions over Rational Field in the powersum basis - sage: s + sage: s # optional - sage.combinat Symmetric Functions over Rational Field in the Schur basis Note that ``e`` is left unchanged:: - sage: e + sage: e # optional - sage.combinat 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() + sage: e == S.e(), h == S.h(), m == S.m(), p == SQ.p(), s == SQ.s() # optional - sage.combinat (True, True, True, True, True) """ from sage.misc.misc import inject_variable @@ -2912,10 +2945,11 @@ def a_realization(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.a_realization() - The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis + sage: A.a_realization() # optional - sage.combinat sage.modules + The subset algebra of {1, 2, 3} over Rational Field + in the Fundamental basis """ def realizations(self): @@ -2925,10 +2959,12 @@ def realizations(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.realizations() - [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.realizations() # optional - sage.combinat 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] .. NOTE:: @@ -2945,20 +2981,22 @@ def facade_for(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.facade_for() - [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.facade_for() # optional - sage.combinat 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 + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: f = A.F().an_element(); f + sage: f = A.F().an_element(); f # optional - sage.combinat sage.modules F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] - sage: i = A.In().an_element(); i + sage: i = A.In().an_element(); i # optional - sage.combinat sage.modules In[{}] + 2*In[{1}] + 3*In[{2}] + In[{1, 2}] - sage: o = A.Out().an_element(); o + sage: o = A.Out().an_element(); o # optional - sage.combinat sage.modules Out[{}] + 2*Out[{1}] + 3*Out[{2}] + Out[{1, 2}] - sage: f in A, i in A, o in A + sage: f in A, i in A, o in A # optional - sage.combinat sage.modules (True, True, True) """ return self.realizations() @@ -2970,9 +3008,9 @@ def super_categories(self): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.Realizations().super_categories() + sage: A.Realizations().super_categories() # optional - sage.combinat sage.modules [Category of realizations of sets] """ return [Sets().Realizations()] @@ -2983,9 +3021,9 @@ def _an_element_(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.an_element() # indirect doctest + sage: A.an_element() # indirect doctest # optional - sage.combinat sage.modules F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] TESTS: @@ -2993,9 +3031,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) - sage: I = M.I() - sage: M._an_element_() + 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 2*E[0] + 2*E[1] + 3*E[2] """ return self.a_realization().an_element() @@ -3008,19 +3046,19 @@ def __contains__(self, x): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.an_element() in A + sage: A.an_element() in A # optional - sage.combinat sage.modules True - sage: A.In().an_element() in A + sage: A.In().an_element() in A # optional - sage.combinat sage.modules True - sage: A.F().an_element() in A + sage: A.F().an_element() in A # optional - sage.combinat sage.modules True - sage: A.Out().an_element() in A + sage: A.Out().an_element() in A # optional - sage.combinat sage.modules True - sage: 1 in A + sage: 1 in A # optional - sage.combinat sage.modules True - sage: QQ['x'].an_element() in A + sage: QQ['x'].an_element() in A # optional - sage.combinat sage.modules False """ return any(x in realization for realization in self.realizations()) @@ -3035,8 +3073,8 @@ def __init_extra__(self): TESTS:: - sage: A = Sets().WithRealizations().example() - sage: A.realizations() # indirect doctest + sage: A = Sets().WithRealizations().example() # optional - sage.combinat sage.modules + sage: A.realizations() # indirect doctest # optional - sage.combinat 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] @@ -3050,11 +3088,11 @@ def realization_of(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In + sage: In = A.In(); In # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: In.realization_of() + sage: In.realization_of() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field """ for category in self.categories(): @@ -3070,11 +3108,11 @@ def _realization_name(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In + sage: In = A.In(); In # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: In._realization_name() + sage: In._realization_name() # optional - sage.combinat sage.modules 'In' """ # The __base__ gets rid of the with_category @@ -3085,9 +3123,9 @@ def _repr_(self): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In + sage: In = A.In(); In # optional - sage.combinat 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 @@ -3099,8 +3137,9 @@ def _repr_(self): sage: from sage.categories.realizations import Realizations sage: class Blah(Parent): ....: pass - sage: P = Blah(category = Sets.WithRealizations.ParentMethods.Realizations(A)) - sage: P # indirect doctest + 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 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 5d01bfab999..a9cc219e06e 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 + sage: W = WeightedIntegerVectors([3,2,1]); W # optional - sage.combinat Integer vectors weighted by [3, 2, 1] - sage: W.subset(4) + sage: W.subset(4) # optional - 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() + sage: Permutations().generating_series() # optional - 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 0e35d866239..87c266858d8 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]]) - sage: S.dimension() + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs + sage: S.dimension() # optional - 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]]) - sage: sorted(S.facets()) + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs + sage: sorted(S.facets()) # optional - 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]]) - sage: S.faces() + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs + sage: S.faces() # optional - 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 bcc7150186d..26e8dffabbb 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() + sage: simplicial_sets.Torus().is_finite() # optional - sage.graphs True - sage: C5 = groups.misc.MultiplicativeAbelian([5]) - sage: simplicial_sets.ClassifyingSpace(C5).is_finite() + sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups + sage: simplicial_sets.ClassifyingSpace(C5).is_finite() # optional - sage.graphs sage.groups False """ return SimplicialSets.Finite() in self.categories() @@ -86,15 +86,15 @@ def is_pointed(self): EXAMPLES:: - 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() + 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 False - sage: Y.is_pointed() + sage: Y.is_pointed() # optional - sage.graphs True """ return SimplicialSets.Pointed() in self.categories() @@ -110,29 +110,29 @@ def set_base_point(self, point): EXAMPLES:: - 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() + 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 w_0 - sage: X_star = X.set_base_point(w) - sage: X_star.base_point() + sage: X_star = X.set_base_point(w) # optional - sage.graphs + sage: X_star.base_point() # optional - sage.graphs w_0 - sage: Y_star = Y.set_base_point(v) - sage: Y_star.base_point() + sage: Y_star = Y.set_base_point(v) # optional - sage.graphs + sage: Y_star.base_point() # optional - sage.graphs v_0 TESTS:: - sage: X.set_base_point(e) + sage: X.set_base_point(e) # optional - sage.graphs Traceback (most recent call last): ... ValueError: the "point" is not a zero-simplex - sage: pt = AbstractSimplex(0) - sage: X.set_base_point(pt) + sage: pt = AbstractSimplex(0) # optional - sage.graphs + sage: X.set_base_point(pt) # optional - sage.graphs Traceback (most recent call last): ... ValueError: the point is not a simplex in this simplicial set @@ -154,8 +154,8 @@ def one(self): EXAMPLES:: - sage: T = simplicial_sets.Torus() - sage: Hom(T, T).identity() + sage: T = simplicial_sets.Torus() # optional - sage.graphs + sage: Hom(T, T).identity() # optional - sage.graphs Simplicial set endomorphism of Torus Defn: Identity map """ @@ -197,13 +197,13 @@ def base_point(self): EXAMPLES:: - 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() + 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 True - sage: S1.base_point() + sage: S1.base_point() # optional - sage.graphs * """ return self._basepoint @@ -226,26 +226,26 @@ def base_point_map(self, domain=None): EXAMPLES:: - sage: T = simplicial_sets.Torus() - sage: f = T.base_point_map(); f + sage: T = simplicial_sets.Torus() # optional - sage.graphs + sage: f = T.base_point_map(); f # optional - sage.graphs Simplicial set morphism: From: Point To: Torus Defn: Constant map at (v_0, v_0) - sage: S3 = simplicial_sets.Sphere(3) - sage: g = S3.base_point_map() - sage: f.domain() == g.domain() + 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 True - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) - 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) - sage: f.domain() == h.domain() + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs + sage: temp = simplicial_sets.Simplex(0) # optional - sage.graphs + sage: pt = temp.set_base_point(temp.n_cells(0)[0]) # optional - sage.graphs + sage: h = RP3.base_point_map(domain=pt) # optional - sage.graphs + sage: f.domain() == h.domain() # optional - sage.graphs False - sage: C5 = groups.misc.MultiplicativeAbelian([5]) - sage: BC5 = simplicial_sets.ClassifyingSpace(C5) - sage: BC5.base_point_map() + 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 Simplicial set morphism: From: Point To: Classifying space of Multiplicative Abelian group isomorphic to C5 @@ -285,49 +285,49 @@ def fundamental_group(self, simplify=True): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) - sage: eight = S1.wedge(S1) - sage: eight.fundamental_group() # free group on 2 generators + 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 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() - sage: K = simplicial_sets.KleinBottle() - sage: X = T.disjoint_union(K) + 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: X_0 = X.set_base_point(X.n_cells(0)[0]) - sage: X_0.fundamental_group().is_abelian() + 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 True - sage: X_1 = X.set_base_point(X.n_cells(0)[1]) - sage: X_1.fundamental_group().is_abelian() + 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 False - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) - sage: RP3.fundamental_group() + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs + sage: RP3.fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < e | e^2 > Compute the fundamental group of some classifying spaces:: - sage: C5 = groups.misc.MultiplicativeAbelian([5]) - sage: BC5 = C5.nerve() - sage: BC5.fundamental_group() + 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 Finitely presented group < e0 | e0^5 > - sage: Sigma3 = groups.permutation.Symmetric(3) - sage: BSigma3 = Sigma3.nerve() - sage: pi = BSigma3.fundamental_group(); pi + 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 Finitely presented group < e1, e2 | e2^2, e1^3, (e2*e1)^2 > - sage: pi.order() + sage: pi.order() # optional - sage.graphs sage.groups 6 - sage: pi.is_abelian() + sage: pi.is_abelian() # optional - sage.graphs sage.groups False The sphere has a trivial fundamental group:: - sage: S2 = simplicial_sets.Sphere(2) - sage: S2.fundamental_group() + sage: S2 = simplicial_sets.Sphere(2) # optional - sage.graphs + sage: S2.fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < | > """ # Import this here to prevent importing libgap upon startup. @@ -578,26 +578,26 @@ def is_simply_connected(self): EXAMPLES:: - sage: T = simplicial_sets.Torus() - sage: T.is_simply_connected() + sage: T = simplicial_sets.Torus() # optional - sage.graphs + sage: T.is_simply_connected() # optional - sage.graphs False - sage: T.suspension().is_simply_connected() + sage: T.suspension().is_simply_connected() # optional - sage.graphs True - sage: simplicial_sets.KleinBottle().is_simply_connected() + sage: simplicial_sets.KleinBottle().is_simply_connected() # optional - sage.graphs False - sage: S2 = simplicial_sets.Sphere(2) - sage: S3 = simplicial_sets.Sphere(3) - sage: (S2.wedge(S3)).is_simply_connected() + 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 True - sage: X = S2.disjoint_union(S3) - sage: X = X.set_base_point(X.n_cells(0)[0]) - sage: X.is_simply_connected() + 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 False - sage: C3 = groups.misc.MultiplicativeAbelian([3]) - sage: BC3 = simplicial_sets.ClassifyingSpace(C3) - sage: BC3.is_simply_connected() + 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 False """ if not self.is_connected(): @@ -641,21 +641,21 @@ def connectivity(self, max_dim=None): EXAMPLES:: - sage: simplicial_sets.Sphere(3).connectivity() + sage: simplicial_sets.Sphere(3).connectivity() # optional - sage.graphs 2 - sage: simplicial_sets.Sphere(0).connectivity() + sage: simplicial_sets.Sphere(0).connectivity() # optional - sage.graphs -1 - sage: K = simplicial_sets.Simplex(4) - sage: K = K.set_base_point(K.n_cells(0)[0]) - sage: K.connectivity() + 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 +Infinity - sage: X = simplicial_sets.Torus().suspension(2) - sage: X.connectivity() + sage: X = simplicial_sets.Torus().suspension(2) # optional - sage.graphs + sage: X.connectivity() # optional - sage.graphs 2 - sage: C2 = groups.misc.MultiplicativeAbelian([2]) - sage: BC2 = simplicial_sets.ClassifyingSpace(C2) - sage: BC2.connectivity() + 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 0 """ if not self.is_connected(): @@ -689,17 +689,17 @@ def unset_base_point(self): EXAMPLES:: - 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() + 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 True - sage: Y.base_point() + sage: Y.base_point() # optional - sage.graphs w_0 - sage: Z = Y.unset_base_point() - sage: Z.is_pointed() + sage: Z = Y.unset_base_point() # optional - sage.graphs + sage: Z.is_pointed() # optional - sage.graphs False """ from sage.topology.simplicial_set import SimplicialSet @@ -718,14 +718,14 @@ def fat_wedge(self, n): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) - sage: S1.fat_wedge(0) + sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs + sage: S1.fat_wedge(0) # optional - sage.graphs Point - sage: S1.fat_wedge(1) + sage: S1.fat_wedge(1) # optional - sage.graphs S^1 - sage: S1.fat_wedge(2).fundamental_group() + sage: S1.fat_wedge(2).fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < e0, e1 | > - sage: S1.fat_wedge(4).homology() + sage: S1.fat_wedge(4).homology() # optional - sage.graphs 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 @@ -745,18 +745,18 @@ def smash_product(self, *others): EXAMPLES:: - 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)) + sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs + sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # optional - sage.graphs + sage: X = S1.smash_product(RP2) # optional - sage.graphs + sage: X.homology(base_ring=GF(2)) # optional - sage.graphs 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) - sage: X = T.smash_product(S1) - sage: X.homology(reduced=False) + 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 {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 77fe3a8982b..cad158f689a 100644 --- a/src/sage/categories/super_algebras.py +++ b/src/sage/categories/super_algebras.py @@ -76,22 +76,22 @@ def tensor(*parents, **kwargs): EXAMPLES:: - sage: A. = ExteriorAlgebra(ZZ); A.rename("A") - sage: T = A.tensor(A,A); T + sage: A. = ExteriorAlgebra(ZZ); A.rename("A") # optional - sage.combinat sage.modules + sage: T = A.tensor(A,A); T # optional - sage.combinat sage.modules A # A # A - sage: T in Algebras(ZZ).Graded().SignedTensorProducts() + sage: T in Algebras(ZZ).Graded().SignedTensorProducts() # optional - sage.combinat sage.modules True - sage: T in Algebras(ZZ).Graded().TensorProducts() + sage: T in Algebras(ZZ).Graded().TensorProducts() # optional - sage.combinat sage.modules False - sage: A.rename(None) + sage: A.rename(None) # optional - sage.combinat sage.modules This also works when the other elements do not have a signed tensor product (:trac:`31266`):: - sage: a = SteenrodAlgebra(3).an_element() - sage: M = CombinatorialFreeModule(GF(3), ['s', 't', 'u']) - sage: s = M.basis()['s'] - sage: tensor([a, s]) + 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 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 2cee5d8ad87..affa3386377 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) - sage: W.graded_algebra() + sage: W. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules + sage: W.graded_algebra() # optional - sage.combinat sage.modules Graded Algebra of Differential Weyl algebra of polynomials in x, y over Rational Field """ @@ -76,27 +76,27 @@ def supercommutator(self, x): EXAMPLES:: - 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) + 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 -5*x*y + 8*x*z - 2*y*z - 6*x + 12*y - 5*z - sage: a.supercommutator(Cl.one()) + sage: a.supercommutator(Cl.one()) # optional - sage.combinat sage.modules 0 - sage: Cl.one().supercommutator(a) + sage: Cl.one().supercommutator(a) # optional - sage.combinat sage.modules 0 - sage: Cl.zero().supercommutator(a) + sage: Cl.zero().supercommutator(a) # optional - sage.combinat sage.modules 0 - sage: a.supercommutator(Cl.zero()) + sage: a.supercommutator(Cl.zero()) # optional - sage.combinat sage.modules 0 - 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()] + 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 [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()] + sage: [a*b-b*a for a in Cl.basis() for b in Cl.basis()] # optional - sage.combinat sage.modules [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 +104,8 @@ def supercommutator(self, x): supercommutators work as well. We verify the exterior algebra is supercommutative:: - sage: E. = ExteriorAlgebra(QQ) - sage: all(b1.supercommutator(b2) == 0 + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: all(b1.supercommutator(b2) == 0 # optional - sage.combinat 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 4fd09867b45..e8974390ba5 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) - sage: a = A.an_element() - sage: a, A.antipode(a) + 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 (6 Q_1 Q_3 P(2,1), Q_1 Q_3 P(2,1)) TESTS:: - sage: E. = ExteriorAlgebra(QQ) - sage: [b.antipode() for b in E.basis()] + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: [b.antipode() for b in E.basis()] # optional - sage.combinat 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) - sage: A._test_antipode() # long time + sage: A = SteenrodAlgebra(7) # optional - sage.combinat sage.modules + sage: A._test_antipode() # long time # optional - 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 849a0fbdb13..82a11f5f2cc 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() + sage: LieConformalAlgebras(AA).Super() # optional - 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',), + sage: bosondict = {('a','a'): {1:{('K',0):1}}} + sage: R = LieConformalAlgebra(QQ, bosondict, names=('a',), # optional - sage.combinat sage.modules ....: central_elements=('K',), super=True) - sage: [g.is_even_odd() for g in R.gens()] + sage: [g.is_even_odd() for g in R.gens()] # optional - sage.combinat sage.modules [0, 0] """ def extra_super_categories(self): @@ -57,7 +57,7 @@ def example(self): EXAMPLES:: - sage: LieConformalAlgebras(QQ).Super().example() + sage: LieConformalAlgebras(QQ).Super().example() # optional - 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,32 +79,33 @@ 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') - sage: V._test_jacobi() # long time (6 seconds) + 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 It works for super Lie conformal algebras too:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: V._test_jacobi() + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: V._test_jacobi() # optional - 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')) - sage: V.inject_variables() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + ....: names=('e', 'h', 'f')) + sage: V.inject_variables() # optional - sage.combinat sage.modules Defining e, h, f, K - sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) + sage: V._test_jacobi(elements=(e, 2*f + h, 3*h)) # optional - 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)) - sage: V._test_jacobi() + sage: wrongdict = {('a', 'a'): {0: {('b', 0): 1}}, + ....: ('b', 'a'): {0: {('a', 0): 1}}} + sage: V = LieConformalAlgebra(QQ, wrongdict, # optional - sage.combinat sage.modules + ....: names=('a', 'b'), parity=(1, 0)) + sage: V._test_jacobi() # optional - sage.combinat sage.modules Traceback (most recent call last): ... - AssertionError: {(0, 0): -3*a} != {} - - {(0, 0): -3*a} - + {} + AssertionError: {(0, 0): -3*a} != {} - {(0, 0): -3*a} + {} """ tester = self._tester(**options) S = tester.some_elements() @@ -162,10 +163,10 @@ def is_even_odd(self): EXAMPLES:: - sage: R = lie_conformal_algebras.NeveuSchwarz(QQ); - sage: R.inject_variables() + sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: R.inject_variables() # optional - sage.combinat sage.modules Defining L, G, C - sage: G.is_even_odd() + sage: G.is_even_odd() # optional - sage.combinat sage.modules 1 """ @@ -175,7 +176,7 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).Super().Graded() + sage: LieConformalAlgebras(AA).Super().Graded() # optional - sage.rings.number_field Category of H-graded super Lie conformal algebras over Algebraic Real Field """ def _repr_object_names(self): @@ -184,7 +185,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).Graded() + sage: LieConformalAlgebras(QQbar).Graded() # optional - 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 091b808408e..2efd5f6e7e2 100644 --- a/src/sage/categories/super_modules.py +++ b/src/sage/categories/super_modules.py @@ -45,7 +45,7 @@ def default_super_categories(cls, category, *args): EXAMPLES:: - sage: HopfAlgebras(ZZ).WithBasis().FiniteDimensional().Super() # indirect doctest + sage: HopfAlgebras(ZZ).WithBasis().FiniteDimensional().Super() # indirect doctest Category of finite dimensional super hopf algebras with basis over Integer Ring """ axioms = axiom_whitelist.intersection(category.axioms()) @@ -183,11 +183,11 @@ def is_even_odd(self): EXAMPLES:: sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) - sage: C.degree_on_basis = sum - sage: C.basis()[2,2,1].is_even_odd() + 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 1 - sage: C.basis()[2,2].is_even_odd() + sage: C.basis()[2,2].is_even_odd() # optional - sage.combinat sage.modules 0 """ return self.degree() % 2 @@ -199,11 +199,11 @@ def is_even(self): EXAMPLES:: sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) - sage: C.degree_on_basis = sum - sage: C.basis()[2,2,1].is_even() + 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 False - sage: C.basis()[2,2].is_even() + sage: C.basis()[2,2].is_even() # optional - sage.combinat sage.modules True """ return self.is_even_odd() == 0 @@ -215,11 +215,11 @@ def is_odd(self): EXAMPLES:: sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) - sage: C.degree_on_basis = sum - sage: C.basis()[2,2,1].is_odd() + 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 True - sage: C.basis()[2,2].is_odd() + sage: C.basis()[2,2].is_odd() # optional - sage.combinat sage.modules 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 7317d42f95c..dff6b54fbe2 100644 --- a/src/sage/categories/super_modules_with_basis.py +++ b/src/sage/categories/super_modules_with_basis.py @@ -53,11 +53,11 @@ def _even_odd_on_basis(self, m): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: C._even_odd_on_basis((0,)) + 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 1 - sage: C._even_odd_on_basis((0,1)) + sage: C._even_odd_on_basis((0,1)) # optional - sage.combinat sage.modules 0 """ return self.degree_on_basis(m) % 2 @@ -70,27 +70,27 @@ def is_super_homogeneous(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x + y - sage: a.is_super_homogeneous() + 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 True - sage: a = x*y + 4 - sage: a.is_super_homogeneous() + sage: a = x*y + 4 # optional - sage.combinat sage.modules + sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules True - sage: a = x*y + x - 3*y + 4 - sage: a.is_super_homogeneous() + sage: a = x*y + x - 3*y + 4 # optional - sage.combinat sage.modules + sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules 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) - sage: a = x*y + 4 - sage: a.is_super_homogeneous() + 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 True - sage: a.is_homogeneous() + sage: a.is_homogeneous() # optional - sage.combinat sage.modules False """ even_odd = self.parent()._even_odd_on_basis @@ -110,22 +110,22 @@ def is_even_odd(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x + y - sage: a.is_even_odd() + 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 1 - sage: a = x*y + 4 - sage: a.is_even_odd() + sage: a = x*y + 4 # optional - sage.combinat sage.modules + sage: a.is_even_odd() # optional - sage.combinat sage.modules 0 - sage: a = x + 4 - sage: a.is_even_odd() + sage: a = x + 4 # optional - sage.combinat sage.modules + sage: a.is_even_odd() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous - sage: E. = ExteriorAlgebra(QQ) - sage: (x*y).is_even_odd() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: (x*y).is_even_odd() # optional - sage.combinat sage.modules 0 """ if not self.support(): @@ -140,18 +140,18 @@ def even_component(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x*y + x - 3*y + 4 - sage: a.even_component() + 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 x*y + 4 TESTS: Check that this really return ``A.zero()`` and not a plain ``0``:: - sage: a = x + y - sage: a.even_component().parent() is C + sage: a = x + y # optional - sage.combinat sage.modules + sage: a.even_component().parent() is C # optional - sage.combinat sage.modules True """ even_odd = self.parent()._even_odd_on_basis @@ -165,18 +165,18 @@ def odd_component(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x*y + x - 3*y + 4 - sage: a.odd_component() + 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 x - 3*y TESTS: Check that this really return ``A.zero()`` and not a plain ``0``:: - sage: a = x*y - sage: a.odd_component().parent() is C + sage: a = x*y # optional - sage.combinat sage.modules + sage: a.odd_component().parent() is C # optional - sage.combinat 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 4cd44e849c9..9cb2f609a8c 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) - sage: E._test_supercommutativity() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: E._test_supercommutativity() # optional - sage.combinat 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]) - sage: E._test_supercommutativity(elements=[x+x*y]) + 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 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 1e15c935599..a68c1d7c591 100644 --- a/src/sage/categories/supercrystals.py +++ b/src/sage/categories/supercrystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs sage.combinat r""" Supercrystals """ @@ -42,11 +43,13 @@ def tensor(self, *crystals, **options): sage: B = crystals.Letters(['A',[1,2]]) sage: C = crystals.Tableaux(['A',[1,2]], shape = [2,1]) sage: T = C.tensor(B); T - Full tensor product of the crystals [Crystal of BKK tableaux of shape [2, 1] of gl(2|3), - The crystal of letters for type ['A', [1, 2]]] + Full tensor product of the crystals + [Crystal of BKK tableaux of shape [2, 1] of gl(2|3), + The crystal of letters for type ['A', [1, 2]]] sage: S = B.tensor(C); S - Full tensor product of the crystals [The crystal of letters for type ['A', [1, 2]], - Crystal of BKK tableaux of shape [2, 1] of gl(2|3)] + Full tensor product of the crystals + [The crystal of letters for type ['A', [1, 2]], + Crystal of BKK tableaux of shape [2, 1] of gl(2|3)] sage: G = T.digraph() sage: H = S.digraph() sage: G.is_isomorphic(H, edge_labels= True) diff --git a/src/sage/categories/triangular_kac_moody_algebras.py b/src/sage/categories/triangular_kac_moody_algebras.py index 95c7881043f..434ff22c1c7 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) - sage: L.f() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L.f() # optional - sage.combinat sage.modules Finite family {1: E[-alpha[1]], 2: E[-alpha[2]]} - sage: L.f(1) + sage: L.f(1) # optional - 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]) - sage: list(L._part_generators(False)) + sage: L = LieAlgebra(QQ, cartan_type=['E', 6]) # optional - sage.combinat sage.modules + sage: list(L._part_generators(False)) # optional - 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) - sage: L.e() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L.e() # optional - sage.combinat sage.modules Finite family {1: E[alpha[1]], 2: E[alpha[2]]} - sage: L.e(1) + sage: L.e(1) # optional - 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) - sage: L.f() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L.f() # optional - sage.combinat sage.modules Finite family {1: E[-alpha[1]], 2: E[-alpha[2]]} - sage: L.f(1) + sage: L.f(1) # optional - 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) - sage: L._negative_half_index_set() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L._negative_half_index_set() # optional - sage.combinat sage.modules [-alpha[2], -alpha[1], -alpha[1] - alpha[2], -alpha[1] - 2*alpha[2]] """ @@ -186,15 +186,15 @@ def _weight_action(self, m, wt): EXAMPLES:: - 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) + 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 1 - sage: L._weight_action(ac[2], mu) + sage: L._weight_action(ac[2], mu) # optional - sage.combinat sage.modules -3/5 - sage: L._weight_action(ac[3], mu) + sage: L._weight_action(ac[3], mu) # optional - sage.combinat sage.modules 0 """ @@ -210,11 +210,11 @@ def verma_module(self, la, basis_key=None, **kwds): EXAMPLES:: - 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 + 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 Verma module with highest weight Lambda[1] + Lambda[2] of Lie algebra of ['A', 2] in the Chevalley basis """ @@ -234,18 +234,18 @@ def part(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type="F4") - sage: L.inject_variables() + sage: L = LieAlgebra(QQ, cartan_type="F4") # optional - sage.combinat sage.modules + sage: L.inject_variables() # optional - sage.combinat sage.modules Defining e1, e2, e3, e4, f1, f2, f3, f4, h1, h2, h3, h4 - sage: e1.part() + sage: e1.part() # optional - sage.combinat sage.modules 1 - sage: f4.part() + sage: f4.part() # optional - sage.combinat sage.modules -1 - sage: (h2 + h3).part() + sage: (h2 + h3).part() # optional - sage.combinat sage.modules 0 - sage: (f1.bracket(f2) + 4*f4).part() + sage: (f1.bracket(f2) + 4*f4).part() # optional - sage.combinat sage.modules -1 - sage: (e1 + f1).part() + sage: (e1 + f1).part() # optional - sage.combinat sage.modules 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 280320474d8..f3d6b565316 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() + sage: GF(4, "a") in UniqueFactorizationDomains() # optional - sage.rings.finite_rings True sage: QQ in UniqueFactorizationDomains() True @@ -123,7 +123,8 @@ def is_unique_factorization_domain(self, proof=True): EXAMPLES:: - sage: Parent(QQ,category=UniqueFactorizationDomains()).is_unique_factorization_domain() + sage: UFD = UniqueFactorizationDomains() + sage: Parent(QQ, category=UFD).is_unique_factorization_domain() True """ @@ -154,16 +155,17 @@ def _gcd_univariate_polynomial(self, f, g): sage: q = (-x^2 - 4*x - 5)*T^2 + (6*x^2 + x + 1)*T + 2*x^2 - x sage: quo,rem=p.pseudo_quo_rem(q); quo,rem ((3*x^4 + 13*x^3 + 19*x^2 + 5*x)*T + 18*x^4 + 12*x^3 + 16*x^2 + 16*x, - (-113*x^6 - 106*x^5 - 133*x^4 - 101*x^3 - 42*x^2 - 41*x)*T - 34*x^6 + 13*x^5 + 54*x^4 + 126*x^3 + 134*x^2 - 5*x - 50) + (-113*x^6 - 106*x^5 - 133*x^4 - 101*x^3 - 42*x^2 - 41*x)*T + - 34*x^6 + 13*x^5 + 54*x^4 + 126*x^3 + 134*x^2 - 5*x - 50) sage: (-x^2 - 4*x - 5)^(3-2+1) * p == quo*q + rem True Check that :trac:`23620` has been resolved:: - sage: R. = ZpFM(2)[] - sage: f = 2*x + 2 - sage: g = 4*x + 2 - sage: f.gcd(g).parent() is R + 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 True """ diff --git a/src/sage/categories/unital_algebras.py b/src/sage/categories/unital_algebras.py index d245b4de8c1..388a6e940a7 100644 --- a/src/sage/categories/unital_algebras.py +++ b/src/sage/categories/unital_algebras.py @@ -61,9 +61,10 @@ def from_base_ring(self, r): EXAMPLES:: - 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.from_base_ring(1) + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - 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 B[word: ] """ return self.one()._lmul_(r) @@ -75,16 +76,18 @@ def __init_extra__(self): EXAMPLES:: - 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 = AlgebrasWithBasis(QQ).example(); A # optional - 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) + sage: coercion_model.discover_coercion(QQ, A) # optional - 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, + 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 + sage: A(1) # indirect doctest # optional - sage.combinat sage.modules B[word: ] TESTS: @@ -92,16 +95,15 @@ def __init_extra__(self): Ensure that :trac:`28328` is fixed and that non-associative algebras are supported:: - sage: class Foo(CombinatorialFreeModule): + sage: class Foo(CombinatorialFreeModule): # optional - sage.modules ....: def one(self): ....: return self.monomial(0) - sage: from sage.categories.magmatic_algebras \ - ....: import MagmaticAlgebras + sage: from sage.categories.magmatic_algebras import MagmaticAlgebras sage: C = MagmaticAlgebras(QQ).WithBasis().Unital() - sage: F = Foo(QQ,(1,),category=C) - sage: F(0) + sage: F = Foo(QQ, (1,), category=C) # optional - sage.modules + sage: F(0) # optional - sage.modules 0 - sage: F(3) + sage: F(3) # optional - sage.modules 3*B[0] sage: class Bar(Parent): @@ -183,8 +185,8 @@ def _coerce_map_from_base_ring(self): Check that :trac:`29312` is fixed:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: F._coerce_map_from_base_ring() + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: F._coerce_map_from_base_ring() # optional - sage.combinat sage.modules Generic morphism: From: Rational Field To: Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field @@ -274,12 +276,12 @@ def one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules word: - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules B[word: ] - sage: A.from_base_ring(4) + sage: A.from_base_ring(4) # optional - sage.combinat sage.modules 4*B[word: ] """ @@ -295,33 +297,33 @@ def one_from_one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules word: - sage: A.one_from_one_basis() + sage: A.one_from_one_basis() # optional - sage.combinat sage.modules B[word: ] - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules B[word: ] TESTS: Try to check that :trac:`5843` Heisenbug is fixed:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: B = AlgebrasWithBasis(QQ).example(('a', 'c')) - sage: A == B + 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 False - sage: Aone = A.one_from_one_basis - sage: Bone = B.one_from_one_basis - sage: Aone is Bone + 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 False Even if called in the wrong order, they should returns their respective one:: - sage: Bone().parent() is B + sage: Bone().parent() is B # optional - sage.combinat sage.modules True - sage: Aone().parent() is A + sage: Aone().parent() is A # optional - sage.combinat sage.modules True """ return self.monomial(self.one_basis()) #. @@ -333,10 +335,10 @@ def one(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules word: - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules B[word: ] """ if self.one_basis is NotImplemented: @@ -348,8 +350,8 @@ def from_base_ring(self): """ TESTS:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.from_base_ring(3) + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.from_base_ring(3) # optional - sage.combinat sage.modules 3*B[word: ] """ if self.one_basis is NotImplemented: @@ -366,12 +368,12 @@ def from_base_ring_from_one_basis(self, r): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.from_base_ring_from_one_basis(3) + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.from_base_ring_from_one_basis(3) # optional - sage.combinat sage.modules 3*B[word: ] - sage: A.from_base_ring(3) + sage: A.from_base_ring(3) # optional - sage.combinat sage.modules 3*B[word: ] - sage: A(3) + sage: A(3) # optional - sage.combinat sage.modules 3*B[word: ] """ return self.term(self.one_basis(), r) diff --git a/src/sage/categories/vector_spaces.py b/src/sage/categories/vector_spaces.py index 66534879b5a..508b0fc1f61 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 - sage: TestSuite(C).run() + sage: C = QQ^10 # vector space # optional - sage.modules + sage: TestSuite(C).run() # optional - 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) + sage: VectorSpaces(QQ)(ZZ^3) # optional - sage.modules Vector space of dimension 3 over Rational Field TESTS: Check whether :trac:`30174` is fixed:: - sage: Q3 = FiniteRankFreeModule(QQ, 3) - sage: Modules(QQ)(Q3) is Q3 + sage: Q3 = FiniteRankFreeModule(QQ, 3) # optional - sage.modules + sage: Modules(QQ)(Q3) is Q3 # optional - sage.modules True """ @@ -162,15 +162,15 @@ def dimension(self): EXAMPLES:: - sage: M = FreeModule(FiniteField(19), 100) - sage: W = M.submodule([M.gen(50)]) - sage: W.dimension() + 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 1 - sage: M = FiniteRankFreeModule(QQ, 3) - sage: M.dimension() + sage: M = FiniteRankFreeModule(QQ, 3) # optional - sage.modules + sage: M.dimension() # optional - sage.modules 3 - sage: M.tensor_module(1,2).dimension() + sage: M.tensor_module(1, 2).dimension() # optional - sage.modules 27 """ @@ -253,7 +253,7 @@ def example(self, base_ring=None): EXAMPLES:: - sage: Modules(QQ).WithBasis().Graded().example() + sage: Modules(QQ).WithBasis().Graded().example() # optional - 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() + sage: Modules(QQ).WithBasis().Graded().example() # optional - 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 ed094d6554d..70f8879353e 100644 --- a/src/sage/categories/weyl_groups.py +++ b/src/sage/categories/weyl_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.groups r""" Weyl Groups """ @@ -182,13 +183,15 @@ def bruhat_cone(self, x, y, side='upper', backend='cdd'): sage: x = W.from_reduced_word([1]) sage: y = W.w0 sage: W.bruhat_cone(x, y) - A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 1 vertex and 2 rays + A 2-dimensional polyhedron in QQ^3 + defined as the convex hull of 1 vertex and 2 rays sage: W = WeylGroup(['E',6]) sage: x = W.one() sage: y = W.w0 sage: W.bruhat_cone(x, y, side='lower') - A 6-dimensional polyhedron in QQ^8 defined as the convex hull of 1 vertex and 6 rays + A 6-dimensional polyhedron in QQ^8 + defined as the convex hull of 1 vertex and 6 rays TESTS:: @@ -242,7 +245,9 @@ def quantum_bruhat_graph(self, index_set=()): sage: W = WeylGroup(['A',3], prefix="s") sage: g = W.quantum_bruhat_graph((1,3)) sage: g - Parabolic Quantum Bruhat Graph of Weyl Group of type ['A', 3] (as a matrix group acting on the ambient space) for nodes (1, 3): Digraph on 6 vertices + Parabolic Quantum Bruhat Graph of Weyl Group of type ['A', 3] + (as a matrix group acting on the ambient space) + for nodes (1, 3): Digraph on 6 vertices sage: g.vertices(sort=True) [s2*s3*s1*s2, s3*s1*s2, s1*s2, s3*s2, s2, 1] sage: g.edges(sort=True) @@ -385,14 +390,16 @@ def left_pieri_factorizations(self, max_length=None): 3 sage: W.from_reduced_word([1,2]).left_pieri_factorizations().cardinality() 2 - sage: [W.from_reduced_word([1,2]).left_pieri_factorizations(max_length=i).cardinality() for i in [-1, 0, 1, 2]] + sage: [W.from_reduced_word([1,2]).left_pieri_factorizations(max_length=i).cardinality() + ....: for i in [-1, 0, 1, 2]] [0, 1, 2, 2] sage: W = WeylGroup(['C',4,1]) sage: w = W.from_reduced_word([0,3,2,1,0]) sage: w.left_pieri_factorizations().cardinality() 7 - sage: [(u.reduced_word(),v.reduced_word()) for (u,v) in w.left_pieri_factorizations()] + sage: [(u.reduced_word(),v.reduced_word()) + ....: for (u,v) in w.left_pieri_factorizations()] [([], [3, 2, 0, 1, 0]), ([0], [3, 2, 1, 0]), ([3], [2, 0, 1, 0]), @@ -460,9 +467,11 @@ def stanley_symmetric_function_as_polynomial(self, max_length=None): 2*x1^3 + x1*x2 sage: W.from_reduced_word([1,2,1,0]).stanley_symmetric_function_as_polynomial() 3*x1^4 + 2*x1^2*x2 + x2^2 + x1*x3 - sage: W.from_reduced_word([1,2,3,1,2,1,0]).stanley_symmetric_function_as_polynomial() # long time + sage: x = W.from_reduced_word([1,2,3,1,2,1,0]) + sage: x.stanley_symmetric_function_as_polynomial() # long time 22*x1^7 + 11*x1^5*x2 + 5*x1^3*x2^2 + 3*x1^4*x3 + 2*x1*x2^3 + x1^2*x2*x3 - sage: W.from_reduced_word([3,1,2,0,3,1,0]).stanley_symmetric_function_as_polynomial() # long time + sage: y = W.from_reduced_word([3,1,2,0,3,1,0]) + sage: y.stanley_symmetric_function_as_polynomial() # long time 8*x1^7 + 4*x1^5*x2 + 2*x1^3*x2^2 + x1*x2^3 sage: W = WeylGroup(['C',3,1]) @@ -516,10 +525,12 @@ def stanley_symmetric_function(self): sage: W = WeylGroup(['A', 3, 1]) sage: W.from_reduced_word([3,1,2,0,3,1,0]).stanley_symmetric_function() - 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] + 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] sage: A = AffinePermutationGroup(['A',3,1]) sage: A.from_reduced_word([3,1,2,0,3,1,0]).stanley_symmetric_function() - 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] + 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] sage: W = WeylGroup(['C',3,1]) sage: W.from_reduced_word([0,2,1,0]).stanley_symmetric_function() @@ -537,10 +548,11 @@ def stanley_symmetric_function(self): sage: A = AffinePermutationGroup(['A',4,1]) sage: a = A([-2,0,1,4,12]) sage: a.stanley_symmetric_function() - 6*m[1, 1, 1, 1, 1, 1, 1, 1] + 5*m[2, 1, 1, 1, 1, 1, 1] + 4*m[2, 2, 1, 1, 1, 1] - + 3*m[2, 2, 2, 1, 1] + 2*m[2, 2, 2, 2] + 4*m[3, 1, 1, 1, 1, 1] + 3*m[3, 2, 1, 1, 1] - + 2*m[3, 2, 2, 1] + 2*m[3, 3, 1, 1] + m[3, 3, 2] + 3*m[4, 1, 1, 1, 1] + 2*m[4, 2, 1, 1] - + m[4, 2, 2] + m[4, 3, 1] + 6*m[1, 1, 1, 1, 1, 1, 1, 1] + 5*m[2, 1, 1, 1, 1, 1, 1] + + 4*m[2, 2, 1, 1, 1, 1] + 3*m[2, 2, 2, 1, 1] + 2*m[2, 2, 2, 2] + + 4*m[3, 1, 1, 1, 1, 1] + 3*m[3, 2, 1, 1, 1] + 2*m[3, 2, 2, 1] + + 2*m[3, 3, 1, 1] + m[3, 3, 2] + 3*m[4, 1, 1, 1, 1] + + 2*m[4, 2, 1, 1] + m[4, 2, 2] + m[4, 3, 1] One more example (:trac:`14095`):: @@ -807,7 +819,8 @@ def quantum_bruhat_successors(self, index_set=None, roots=False, quantum_only=Fa sage: w.quantum_bruhat_successors([1,3]) Traceback (most recent call last): ... - ValueError: s2*s3 is not of minimum length in its coset of the parabolic subgroup generated by the reflections (1, 3) + ValueError: s2*s3 is not of minimum length in its coset + of the parabolic subgroup generated by the reflections (1, 3) """ W = self.parent() if not W.cartan_type().is_finite(): diff --git a/src/sage/categories/with_realizations.py b/src/sage/categories/with_realizations.py index 7f59b92d72b..dd463186a2a 100644 --- a/src/sage/categories/with_realizations.py +++ b/src/sage/categories/with_realizations.py @@ -69,45 +69,46 @@ def WithRealizations(self): represented. Consider for example an algebra `A` which admits several natural bases:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat 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() + sage: A.F() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis - sage: A.Out() + sage: A.Out() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the Out basis - sage: A.In() + sage: A.In() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: A.an_element() + sage: A.an_element() # optional - sage.combinat sage.modules 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() - sage: i = In.an_element(); i + 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 In[{}] + 2*In[{1}] + 3*In[{2}] + In[{1, 2}] - sage: F(i) + sage: F(i) # optional - sage.combinat sage.modules 7*F[{}] + 3*F[{1}] + 4*F[{2}] + F[{1, 2}] - sage: F.coerce_map_from(Out) + sage: F.coerce_map_from(Out) # optional - sage.combinat sage.modules 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) - 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}] + sage: (1 + Out.from_set(1)) * In.from_set(2,3) # optional - 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() + sage: A.realizations() # optional - sage.combinat 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] @@ -115,10 +116,13 @@ def WithRealizations(self): Instead of manually defining the shorthands ``F``, ``In``, and ``Out``, as above one can just do:: - sage: A.inject_shorthands() - Defining F as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis - Defining In as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the In basis - Defining Out as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Out basis + sage: A.inject_shorthands() # optional - 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 + The subset algebra of {1, 2, 3} over Rational Field in the In basis + Defining Out as shorthand for + The subset algebra of {1, 2, 3} over Rational Field in the Out basis .. RUBRIC:: Rationale @@ -138,26 +142,28 @@ def WithRealizations(self): We now illustrate this second point by defining the polynomial ring with coefficients in `A`:: - sage: P = A['x']; P - Univariate Polynomial Ring in x over The subset algebra of {1, 2, 3} over Rational Field - sage: x = P.gen() + sage: P = A['x']; P # optional - sage.combinat 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 In the following examples, the coefficients turn out to be all represented in the `F` basis:: - sage: P.one() + sage: P.one() # optional - sage.combinat sage.modules F[{}] - sage: (P.an_element() + 1)^2 + sage: (P.an_element() + 1)^2 # optional - sage.combinat 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 + sage: p = P([1, In[{1}], Out[{2}] ]); p # optional - sage.combinat sage.modules Out[{2}]*x^2 + In[{1}]*x + F[{}] - sage: p^2 + sage: p^2 # optional - 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 + + (-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 + (F[{}] + 3*F[{1}] + 2*F[{2}] - 2*F[{1, 2}] - 2*F[{2, 3}] + 2*F[{1, 2, 3}])*x^2 + (2*F[{}] + 2*F[{1}])*x + F[{}] @@ -169,16 +175,21 @@ def WithRealizations(self): One can easily coerce all coefficient to a given basis with:: - sage: p.map_coefficients(In) - (-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[{}] + sage: p.map_coefficients(In) # optional - 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[{}] Alas, the natural notation for constructing such polynomials does not yet work:: - sage: In[{1}] * x + sage: In[{1}] * x # optional - sage.combinat sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'The subset algebra of {1, 2, 3} over Rational Field in the In basis' and 'Univariate Polynomial Ring in x over The subset algebra of {1, 2, 3} over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'The subset algebra of {1, 2, 3} over Rational Field in the In basis' + and 'Univariate Polynomial Ring in x over + The subset algebra of {1, 2, 3} over Rational Field' .. RUBRIC:: The category of realizations of `A` @@ -186,17 +197,18 @@ def WithRealizations(self): is a category (whose class inherits from :class:`~sage.categories.realizations.Category_realization_of_parent`):: - sage: A.Realizations() - Category of realizations of The subset algebra of {1, 2, 3} over Rational Field + sage: A.Realizations() # optional - sage.combinat 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() + sage: A.F() in A.Realizations() # optional - sage.combinat sage.modules True `A` itself is in the category of algebras with realizations:: - sage: A in Algebras(QQ).WithRealizations() + sage: A in Algebras(QQ).WithRealizations() # optional - sage.combinat sage.modules True The (mostly technical) ``WithRealizations`` categories are the @@ -216,12 +228,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() + sage: A in Rings().WithRealizations() # optional - sage.combinat sage.modules True and in the category of algebras (regressiveness):: - sage: A in Algebras(QQ) + sage: A in Algebras(QQ) # optional - sage.combinat sage.modules True .. NOTE::