ModulesWithBasis

class sage.categories.modules_with_basis.DiagonalModuleMorphism(diagonal, domain, codomain=None, category=None)

Bases: sage.categories.modules_with_basis.ModuleMorphismByLinearity

A class for diagonal module morphisms.

See module_morphism() of ModulesWithBasis

Todo:

  • implement an optimized _call_ function
  • generalize to a mapcoeffs
  • generalize to a mapterms
class sage.categories.modules_with_basis.ModuleMorphismByLinearity(domain, on_basis=None, position=0, zero=None, codomain=None, category=None)

Bases: sage.categories.morphism.Morphism

A class for module morphisms obtained by extending a function by linearity

on_basis()

Returns the action of this morphism on basis elements, as per ModulesWithBasis.HomCategory.ElementMethods.on_basis().

OUTPUT:

  • a function from the indices of the basis of the domain to the codomain.

EXAMPLES:

sage: X = CombinatorialFreeModule(ZZ, [-2, -1, 1, 2])
sage: Y = CombinatorialFreeModule(ZZ, [1, 2])
sage: phi_on_basis = Y.monomial * abs
sage: phi = sage.categories.modules_with_basis.ModuleMorphismByLinearity(X, on_basis = phi_on_basis, codomain = Y)
sage: x = X.basis()
sage: phi.on_basis()(-2)
B[2]
sage: phi.on_basis() == phi_on_basis
True

Note: could probably be inherited from the categories

class sage.categories.modules_with_basis.ModulesWithBasis(base, name=None)

Bases: sage.categories.category_types.Category_over_base_ring, sage.categories.cartesian_product.CategoryWithCartesianProduct, sage.categories.tensor.CategoryWithTensorProduct

The category of modules with a distinguished basis

The elements are represented by expanding them in the distinguished basis. The morphisms are not required to respect the distinguished basis.

EXAMPLES:

sage: ModulesWithBasis(ZZ)
Category of modules with basis over Integer Ring
sage: ModulesWithBasis(ZZ).super_categories()
[Category of modules over Integer Ring]

If the base ring is actually a field, this is a subcategory of the category of abstract vector fields:

sage: ModulesWithBasis(RationalField()).super_categories()
[Category of vector spaces over Rational Field]

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 modules 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
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)
0

TESTS:

sage: f = H.zero().on_basis()
sage: f(1)
0
sage: f(2)
0

EXAMPLES:

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
Generic morphism:
  From: X
  To:   Y
sage: phi(x)
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)
(B[3], B[4])

Hom(X,Y) has a natural module structure (except for the zero, the operations are not yet implemented though). However since the dimension is not necessarily finite, it is not a module with basis; but see FiniteDimensionalModulesWithBasis and GradedModulesWithBasis:

sage: H in ModulesWithBasis(QQ), H in Modules(QQ)
(False, True)

Some more playing around with categories and higher order homsets:

sage: H.category()
Category of hom sets in Category of modules with basis over Rational Field
sage: Hom(H, H).category()
Category of hom sets in Category of modules over Rational Field

# TODO: End(X) is an algebra

TESTS:

sage: TestSuite(ModulesWithBasis(ZZ)).run()
class CartesianProductCategory(category, name=None)

Bases: sage.categories.cartesian_product.CartesianProductCategory

The category of modules with basis constructed by cartesian products of modules with basis

ParentMethods
alias of CartesianProductCategory.ParentMethods
super_categories(*args, **kwds)

EXAMPLES:

sage: ModulesWithBasis(QQ).cartesian_product_category().super_categories()
[Category of modules with basis over Rational Field]
class ModulesWithBasis.ElementMethods

Bases: sage.categories.tensor.CategoryWithTensorProduct.ElementMethods, sage.categories.cartesian_product.CategoryWithCartesianProduct.ElementMethods

leading_coefficient(cmp=None)

Returns the leading coefficient of self.

This is the coefficient of the term whose corresponding basis element is maximal. Note that this may not be the term which actually appears first when self is printed. If the default term ordering is not what is desired, a comparison function, cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
1
sage: def cmp(x,y): return y-x
sage: x.leading_coefficient(cmp=cmp)
3

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.leading_coefficient()
-5
leading_item(cmp=None)

Returns the pair (k, c) where c * (the basis elt. indexed by k) is the leading term of self.

‘leading term’ means that the corresponding basis element is maximal. Note that this may not be the term which actually appears first when self is printed. If the default term ordering is not what is desired, a comparison function, cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
(3, 4)
sage: def cmp(x,y): return y-x
sage: x.leading_item(cmp=cmp)
(1, 3)

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.leading_item()
([3], -5)
leading_monomial(cmp=None)

Returns the leading monomial of self.

This is the monomial whose corresponding basis element is maximal. Note that this may not be the term which actually appears first when self is printed. If the default term ordering is not what is desired, a comparison function, cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
B[3]
sage: def cmp(x,y): return y-x
sage: x.leading_monomial(cmp=cmp)
B[1]

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.leading_monomial()
s[3]
leading_support(cmp=None)

Returns the maximal element of the support of self. Note that this may not be the term which actually appears first when self is printed.

If the default ordering of the basis elements is not what is desired, a comparison function, cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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_support()
3
sage: def cmp(x,y): return y-x
sage: x.leading_support(cmp=cmp)
1

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.leading_support()
[3]
leading_term(cmp=None)

Returns the leading term of self.

This is the term whose corresponding basis element is maximal. Note that this may not be the term which actually appears first when self is printed. If the default term ordering is not what is desired, a comparison function, cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
B[3]
sage: def cmp(x,y): return y-x
sage: x.leading_term(cmp=cmp)
3*B[1]

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.leading_term()
-5*s[3]
support_of_term()

INPUT:

  • self - a monomial, possibly with coefficient

Returns the support of self.

EXAMPLES:

sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X")
sage: X.monomial(2).support_of_term()
2
sage: X.term(3, 2).support_of_term()
3

An exception is raised if self has more than one term:

sage: (X.monomial(2) + X.monomial(3)).support_of_term() Traceback (most recent call last): ... ValueError: B[2] + B[3] is not a single term
trailing_coefficient(cmp=None)

Returns the trailing coefficient of self.

This is the coefficient of the monomial whose corresponding basis element is minimal. Note that this may not be the term which actually appears last when self is printed. If the default term ordering is not what is desired, a comparison function cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
3
sage: def cmp(x,y): return y-x
sage: x.trailing_coefficient(cmp=cmp)
1

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.trailing_coefficient()
2
trailing_item(cmp=None)

Returns the pair (c, k) where c*self.parent().monomial(k) is the trailing term of self.

This is the monomial whose corresponding basis element is minimal. Note that this may not be the term which actually appears last when self is printed. If the default term ordering is not what is desired, a comparison function cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
(1, 3)
sage: def cmp(x,y): return y-x
sage: x.trailing_item(cmp=cmp)
(3, 1)

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.trailing_item()
([1], 2)
trailing_monomial(cmp=None)

Returns the trailing monomial of self.

This is the monomial whose corresponding basis element is minimal. Note that this may not be the term which actually appears last when self is printed. If the default term ordering is not what is desired, a comparison function cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
B[1]
sage: def cmp(x,y): return y-x
sage: x.trailing_monomial(cmp=cmp)
B[3]

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.trailing_monomial()
s[1]
trailing_support(cmp=None)

Returns the minimal element of the support of self. Note that this may not be the term which actually appears last when self is printed.

If the default ordering of the basis elements is not what is desired, a comparison function, cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
1
sage: def cmp(x,y): return y-x
sage: x.trailing_support(cmp=cmp)
3

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.trailing_support()
[1]
trailing_term(cmp=None)

Returns the trailing term of self.

This is the term whose corresponding basis element is minimal. Note that this may not be the term which actually appears last when self is printed. If the default term ordering is not what is desired, a comparison function cmp(x,y), can be provided. This should return a negative value if x < y, 0 if x == y and a positive value if x > y.

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()
3*B[1]
sage: def cmp(x,y): return y-x
sage: x.trailing_term(cmp=cmp)
B[3]

sage: s = SymmetricFunctions(QQ).schur()
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3]
sage: f.trailing_term()
2*s[1]
class ModulesWithBasis.HomCategory(category, name=None)

Bases: sage.categories.category.HomCategory

The category of homomorphisms sets Hom(X,Y) for X, Y modules with basis

ElementMethods
alias of HomCategory.ElementMethods
ParentMethods
alias of HomCategory.ParentMethods
class ModulesWithBasis.ParentMethods

Bases: sage.categories.tensor.CategoryWithTensorProduct.ParentMethods, sage.categories.cartesian_product.CategoryWithCartesianProduct.ParentMethods

module_morphism(on_basis=None, diagonal=None, triangular=None, **keywords)

Constructs functions by linearity

INPUT:

  • self - a parent X in ModulesWithBasis(R), with basis x indexed by I
  • codomain - the codomain Y of f: defaults to f.codomain if the later is defined
  • zero - the zero of the codomain; defaults to codomain.zero() or 0 if codomain is not specified
  • position - a non negative integer; defaults to 0
  • on_basis - a function f which accepts elements of I as position-th argument and returns elements of Y
  • diagonal - a function d from I to R
  • triangular a boolean (default: False)
  • category - a category. By default, this is ModulesWithBasis(R) if Y is in this category, and otherwise this lets Hom(X,Y) decide

Exactly one of on_basis and diagonal options should be specified.

With the on_basis option, this returns a function g obtained by extending f by linearity on the position-th positional argument. For example, for position == 1 and a ternary function f, and denoting by x_i the basis of X, one has:

g(a, \sum \lambda_i x_i, c) = \sum \lambda_i f(a, i, c)

EXAMPLES:

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: phi
Generic morphism:
From: X
To:   Y
sage: x = X.basis()
sage: phi(x[1] + x[3])
B[1] + 2*B[2] + B[3] + 2*B[4]

With the diagonal argument, this returns the module morphism g such that:

g(x_i) = d(i) y_i

This assumes that the respective bases x and y of X and Y have the same index set I.

With triangular = upper, the constructed module morphism is assumed to be upper triangular; that is its matrix in the distinguished basis of X and Y would be upper triangular with invertible elements on its diagonal. This currently assumes that X and Y have the same index set I. This is used to compute preimages and inverting the morphism:

sage: I = 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])
B[1] + B[2]
sage: phi(x[6])
B[1] + B[2] + B[3] + B[6]
sage: phi(x[30])
B[1] + B[2] + B[3] + B[5] + B[6] + B[10] + B[15] + B[30]
sage: phi.preimage(y[2])
-B[1] + B[2]
sage: phi.preimage(y[6])
B[1] - B[2] - B[3] + B[6]
sage: phi.preimage(y[30])
-B[1] + B[2] + B[3] + B[5] - B[6] - B[10] - B[15] + B[30]
sage: (phi^-1)(y[30])
-B[1] + B[2] + B[3] + B[5] - B[6] - B[10] - B[15] + B[30]

For details and further optional arguments, see sage.categories.modules_with_basis.TriangularModuleMorphism.

Caveat: the returned element is in Hom(codomain, domain, category). This is only correct for unary functions.

Todo: should codomain be self by default in the diagonal and triangular cases?

class ModulesWithBasis.TensorCategory(category, name=None)

Bases: sage.categories.tensor.TensorCategory

The category of modules with basis constructed by tensor product of modules with basis

ElementMethods
alias of TensorCategory.ElementMethods
ParentMethods
alias of TensorCategory.ParentMethods
super_categories(*args, **kwds)

EXAMPLES:

sage: ModulesWithBasis(QQ).tensor_category().super_categories()
[Category of modules with basis over Rational Field]
ModulesWithBasis.is_abelian()

Returns whether this category is abelian

This is the case if and only if the base ring is a field.

EXAMPLES:

sage: ModulesWithBasis(QQ).is_abelian()
True
sage: ModulesWithBasis(ZZ).is_abelian()
False
ModulesWithBasis.super_categories(*args, **kwds)

EXAMPLES:

sage: ModulesWithBasis(QQ).super_categories()
[Category of vector spaces over Rational Field]
sage: ModulesWithBasis(ZZ).super_categories()
[Category of modules over Integer Ring]
class sage.categories.modules_with_basis.PointwiseInverseFunction(f)

Bases: sage.structure.sage_object.SageObject

A class for point wise inverse functions

EXAMPLES:
sage: from sage.categories.modules_with_basis import PointwiseInverseFunction sage: f = PointwiseInverseFunction(factorial) sage: f(0), f(1), f(2), f(3) (1, 1, 1/2, 1/6)
pointwise_inverse()
TESTS:
sage: from sage.categories.modules_with_basis import PointwiseInverseFunction sage: g = PointwiseInverseFunction(operator.mul) sage: g.pointwise_inverse() is operator.mul True
class sage.categories.modules_with_basis.TriangularModuleMorphism(on_basis, domain, triangular='upper', unitriangular=False, codomain=None, category=None, cmp=None, inverse=None, **keywords)

Bases: sage.categories.modules_with_basis.ModuleMorphismByLinearity

A class for triangular module morphisms; that is module morphisms from X to Y whose matrix in the distinguished basis of X and Y would be upper triangular with invertible elements on its diagonal. This currently assumes that X and Y have the same index set I. However, I needs not be finite.

See module_morphism() of ModulesWithBasis

EXAMPLES:

sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis()
sage: def ut(i): return sum(j*x[j] for j in range(i,4))
sage: import __main__; __main__.ut = ut
sage: phi = X.module_morphism(ut, triangular="lower", codomain = X)
sage: phi(x[2])
2*B[2] + 3*B[3]
sage: phi.preimage(x[2])
1/2*B[2] - 1/2*B[3]
sage: phi(phi.preimage(x[2]))
B[2]
preimage(f)

Returns the image of f by the inverse of self.

TESTS::
sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); x = X.basis() sage: Y = CombinatorialFreeModule(QQ, [1, 2, 3]); y = Y.basis() sage: uut = lambda i: sum( y[j] for j in range(i,4) ) # uni-upper sage: phi = X.module_morphism(uut, triangular=True, codomain = Y) sage: phi.preimage(y[1] + y[2]) B[1] - B[3]
sage.categories.modules_with_basis.pointwise_inverse_function(f)
INPUT:
  • f: a function

Returns the function (...) -> 1 / f(...)

EXAMPLES:
sage: from sage.categories.modules_with_basis import pointwise_inverse_function sage: def f(x): return x ... sage: g = pointwise_inverse_function(f) sage: g(1), g(2), g(3) (1, 1/2, 1/3)

pointwise_inverse_function is an involution:

sage: f is pointwise_inverse_function(g) True

Todo: this has nothing to do here!!! Should there be a library for pointwise operations on functions somewhere in Sage?

Previous topic

Modules

Next topic

MonoidAlgebras

This Page