Free modules

class sage.combinat.free_module.CombinatorialFreeModule(R, cc, element_class=<class 'sage.combinat.free_module.CombinatorialFreeModuleElement'>, prefix='B')

EXAMPLES: We construct a free module whose basis is indexed by the letters a,b,c:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: F
Free module generated by ['a', 'b', 'c'] over Rational Field

Its basis is a family, indexed by a,b,c: Caveat in family: the order of the indices is not preserved

sage: e = F.basis()
sage: list(sorted(e.keys()))
['a', 'b', 'c']
sage: list(sorted(e))
[B['a'], B['b'], B['c']]

Let us construct some elements, and compute with them:

sage: e['a']
B['a']
sage: 2*e['a']
2*B['a']
sage: e['a'] + 3*e['b']
B['a'] + 3*B['b']
__init__(R, cc, element_class=<class 'sage.combinat.free_module.CombinatorialFreeModuleElement'>, prefix='B')

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: F == loads(dumps(F))
True
class sage.combinat.free_module.CombinatorialFreeModuleElement(M, x)
__cmp__(left, right)

The ordering is the one on the underlying sorted list of (monomial,coefficients) pairs.

EXAMPLES:

sage: s = SFASchur(QQ)
sage: a = s([2,1])
sage: b = s([1,1,1])
sage: cmp(a,b) #indirect doctest
1
__contains__(x)

Returns whether or not a combinatorial object x indexing a basis element is in the support of self.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] + 3*B['c']
sage: 'a' in f
True
sage: 'b' in f
False
sage: s = SFASchur(QQ)
sage: a = s([2,1]) + s([3])
sage: Partition([2,1]) in a
True
sage: Partition([1,1,1]) in a
False
__div__(x)

Division by coefficients

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, [1,2,3])
sage: x = F._from_dict({1:2, 2:3})
sage: x/2
B[1] + 3/2*B[2]
sage: F = CombinatorialFreeModule(QQ, [1,2,3])
sage: B = F.basis()
sage: f = 2*B[2] + 4*B[3]
sage: f/2
B[2] + 2*B[3]
__getitem__(m, default=None)

Returns the coefficient of m in self, where m is key in self._monomial_coefficients.

EXAMPLES:

sage: p = Partition([2,1])
sage: q = Partition([1,1,1])
sage: s = SFASchur(QQ)
sage: a = s(p)
sage: a._coefficient_fast([2,1])
...
TypeError: unhashable type: 'list'
sage: a._coefficient_fast(p)
1
sage: a._coefficient_fast(p, 2)
1
sage: a._coefficient_fast(q)
0
sage: a._coefficient_fast(q, 2)
2
sage: a[p]
1
sage: a[q]
0
__init__(M, x)

Create a combinatorial module element x. This should never be called directly, but only through the parent combinatorial module’s __call__ method.

TESTS:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] + 3*B['c']; f
B['a'] + 3*B['c']
sage: f == loads(dumps(f))
True
__iter__()

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] + 3*B['c']
sage: [i for i in sorted(f)]
[('a', 1), ('c', 3)]
sage: s = SFASchur(QQ)
sage: a = s([2,1]) + s([3])
sage: [i for i in sorted(a)]
[([2, 1], 1), ([3], 1)]
__len__()

Returns the number of basis elements of self with nonzero coefficients.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] - 3*B['c']
sage: len(f)
2
sage: s = SFASchur(QQ)
sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1])
sage: len(z)
4
__repr__()

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'], prefix='F')
sage: e = F.basis()
sage: e['a'] + 2*e['b']
F['a'] + 2*F['b']
__weakref__
list of weak references to the object (if defined)
_add_(y)

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: B['a'] + 3*B['c']
B['a'] + 3*B['c']
sage: s = SFASchur(QQ)
sage: s([2,1]) + s([5,4]) # indirect doctest
s[2, 1] + s[5, 4]
sage: a = s([2,1]) + 0
sage: len(a.monomial_coefficients())
1
_coefficient_fast(m, default=None)

Returns the coefficient of m in self, where m is key in self._monomial_coefficients.

EXAMPLES:

sage: p = Partition([2,1])
sage: q = Partition([1,1,1])
sage: s = SFASchur(QQ)
sage: a = s(p)
sage: a._coefficient_fast([2,1])
...
TypeError: unhashable type: 'list'
sage: a._coefficient_fast(p)
1
sage: a._coefficient_fast(p, 2)
1
sage: a._coefficient_fast(q)
0
sage: a._coefficient_fast(q, 2)
2
sage: a[p]
1
sage: a[q]
0
_l_action(x)

Returns the action of a scalar on self when self is on the left (and the scalar is on the right).

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: B['a']*1/2
1/2*B['a']
_latex_()

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] + 3*B['c']
sage: latex(f)
B_{a} + 3B_{c}
sage: QS3 = SymmetricGroupAlgebra(QQ,3)
sage: a = 2 + QS3([2,1,3])
sage: latex(a) #indirect doctest
2[1,2,3] + [2,1,3]
_neg_()

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] + 3*B['c']
sage: -f
-B['a'] - 3*B['c']
sage: s = SFASchur(QQ)
sage: -s([2,1]) # indirect doctest
-s[2, 1]
_r_action(x)

Returns the action of a scalar on self when self is on the right (and the scalar is on the left).

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: 1/2*B['a']
1/2*B['a']
_sub_(y)

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: B['a'] - 3*B['c']
B['a'] - 3*B['c']
sage: s = SFASchur(QQ)
sage: s([2,1]) - s([5,4]) # indirect doctest
s[2, 1] - s[5, 4]
_vector_(new_BR=None)

Returns a vector version of self. If new_BR is specified, then in returns a vector over new_BR.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] - 3*B['c']
sage: vector(f)
(1, 0, -3)
sage: QS3 = SymmetricGroupAlgebra(QQ, 3)
sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1])
sage: a._vector_()
(2, 0, 0, 0, 0, 4)
sage: vector(a)
(2, 0, 0, 0, 0, 4)
sage: a._vector_(RDF)
(2.0, 0.0, 0.0, 0.0, 0.0, 4.0)
coefficient(m)

EXAMPLES:

sage: s = SFASchur(QQ)
sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1])
sage: z.coefficient([4])
1
sage: z.coefficient([2,1])
-2
coefficients()

Returns a list of the coefficients appearing on the basiselements in self.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] - 3*B['c']
sage: f.coefficients()
[1, -3]
sage: s = SFASchur(QQ)
sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1])
sage: z.coefficients()
[1, 1, 1, 1]
is_zero()

Returns True if and only self == 0.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] - 3*B['c']
sage: f.is_zero()
False
sage: F(0).is_zero()
True
sage: s = SFASchur(QQ)
sage: s([2,1]).is_zero()
False
sage: s(0).is_zero()
True
sage: (s([2,1]) - s([2,1])).is_zero()
True
length()

Returns the number of basis elements of self with nonzero coefficients.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] - 3*B['c']
sage: f.length()
2
sage: s = SFASchur(QQ)
sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1])
sage: z.length()
4
map_coefficients(f)

Returns a new element of self.parent() obtained by applying the function f to all of the coefficients of self.

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)
6*B['a'] + 2*B['c']
sage: s = SFASchur(QQ)
sage: a = s([2,1])+2*s([3,2])
sage: a.map_coefficients(lambda x: x*2)
2*s[2, 1] + 4*s[3, 2]
map_mc(f)

Returns a new element of self.parent() obtained by applying the function f to a monomial coefficient (m,c) pair. f returns a (new_m, new_c) pair.

EXAMPLES:

sage: s = SFASchur(QQ)
sage: f = lambda m,c: (m.conjugate(), 2*c)
sage: a = s([2,1]) + s([1,1,1])
sage: a.map_monomial(f)
2*s[2, 1] + 2*s[3]
map_monomial(f)

Returns a new element of self.parent() obtained by applying the function f to a monomial coefficient (m,c) pair. f returns a (new_m, new_c) pair.

EXAMPLES:

sage: s = SFASchur(QQ)
sage: f = lambda m,c: (m.conjugate(), 2*c)
sage: a = s([2,1]) + s([1,1,1])
sage: a.map_monomial(f)
2*s[2, 1] + 2*s[3]
map_support(f)

Returns a new element of self.parent() obtained by applying the function f to all of the combinatorial objects indexing the basis elements.

EXAMPLES:

sage: s = SFASchur(QQ)
sage: a = s([2,1])+2*s([3,2])
sage: a.map_support(lambda x: x.conjugate())
s[2, 1] + 2*s[2, 2, 1]
monomial_coefficients()

Return the internal dictionary which has the combinatorial objects indexing the basis as keys and their corresponding coefficients as values.

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']
1
sage: d['c']
3
sage: s = SFASchur(QQ)
sage: a = s([2,1])+2*s([3,2])
sage: d = a.monomial_coefficients()
sage: type(d)
<type 'dict'>
sage: d[ Partition([2,1]) ]
1
sage: d[ Partition([3,2]) ]
2
monomials()

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] + 2*B['c']
sage: f.monomials()
[B['a'], B['c']]
support()

Returns a list of the combinatorial objects indexing the basis elements of self which non-zero coefficients.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] - 3*B['c']
sage: f.support()
['a', 'c']
sage: s = SFASchur(QQ)
sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1])
sage: z.support()
[[1], [1, 1, 1], [2, 1], [4]]
terms()

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] + 2*B['c']
sage: f.terms()
[B['a'], 2*B['c']]
to_vector()

Returns a vector version of self.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: B = F.basis()
sage: f = B['a'] - 3*B['c']
sage: f.to_vector()
(1, 0, -3)
sage: QS3 = SymmetricGroupAlgebra(QQ, 3)
sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1])
sage: a.to_vector()
(2, 0, 0, 0, 0, 4)
class sage.combinat.free_module.CombinatorialFreeModuleInterface(R, element_class)
__call__(x)

Coerce x into self.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ,[0,1])
sage: F(0)
0
sage: F(1)
...
TypeError: do not know how to make x (= 1) an element of Free module generated by [0, 1] over Rational Field
sage: QS3 = SymmetricGroupAlgebra(QQ,3)
sage: QS3(2)
2*[1, 2, 3]
sage: QS3([2,3,1])
[2, 3, 1]
__cmp__(other)

EXAMPLES:

sage: XQ = SchubertPolynomialRing(QQ)
sage: XZ = SchubertPolynomialRing(ZZ)
sage: XQ == XZ #indirect doctest
False
sage: XQ == XQ
True
__init__(R, element_class)
__repr__()

EXAMPLES:

sage: QS3 = SymmetricGroupAlgebra(QQ,3)
sage: print QS3.__repr__()
Symmetric group algebra of order 3 over Rational Field
_an_element_impl()

Returns an element of self, namely the zero element.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F._an_element_impl()
0
sage: _.parent() is F
True
_apply_module_endomorphism(a, f)

This takes in a function from the basis elements to the elements of self and applies it linearly to a. Note that _apply_module_endomorphism does not require multiplication on self to be defined.

EXAMPLES:

sage: s = SFASchur(QQ)
sage: f = lambda part: 2*s(part.conjugate())
sage: s._apply_module_endomorphism( s([2,1]) + s([1,1,1]), f)
2*s[2, 1] + 2*s[3]
_apply_module_morphism(x, f)

Returns the image of x under the module morphism defined by extending f by linearity.

INPUT:

  • x : a element of self
  • ``f``f - a function that takes in a combinatorial object indexing a basis element and returns an element of the target domain

EXAMPLES:

sage: s = SFASchur(QQ)
sage: a = s([3]) + s([2,1]) + s([1,1,1])
sage: b = 2*a
sage: f = lambda part: len(part)
sage: s._apply_module_morphism(a, f) #1+2+3
6
sage: s._apply_module_morphism(b, f) #2*(1+2+3)
12
_from_dict(d, coerce=False)

Given a monomial coefficient dictionary d, return the element of self with the dictionary.

EXAMPLES:

sage: e = SFAElementary(QQ)
sage: s = SFASchur(QQ)
sage: a = e([2,1]) + e([1,1,1]); a
e[1, 1, 1] + e[2, 1]
sage: s._from_dict(a.monomial_coefficients())
s[1, 1, 1] + s[2, 1]
sage: part = Partition([2,1])
sage: d = {part:1}
sage: a = s._from_dict(d,coerce=True); a
s[2, 1]
sage: a.coefficient(part).parent()
Rational Field
basis()

Returns the basis of self.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: F.basis()
Finite family {'a': B['a'], 'c': B['c'], 'b': B['b']}
sage: QS3 = SymmetricGroupAlgebra(QQ,3)
sage: list(QS3.basis())
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
combinatorial_class()

Returns the combinatorial class that indexes the basis elements.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F.combinatorial_class()
Combinatorial class with elements in ['a', 'b', 'c']
sage: s = SFASchur(QQ)
sage: s.combinatorial_class()
Partitions
dimension()

Returns the dimension of the combinatorial algebra (which is given by the number of elements in the associated combinatorial class).

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F.dimension()
3
sage: s = SFASchur(QQ)
sage: s.dimension()
+Infinity
get_order()

Returns the order of the elements in the basis.

EXAMPLES:

sage: QS2 = SymmetricGroupAlgebra(QQ,2)
sage: QS2.get_order()
[[1, 2], [2, 1]]
prefix()

Returns the prefix used when displaying elements of self.

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F.prefix()
'B'
sage: X = SchubertPolynomialRing(QQ)
sage: X.prefix()
'X'
set_order(order)

Sets the order of the elements of the combinatorial class.

If .set_order() has not been called, then the ordering is the one used in the generation of the elements of self’s associated combinatorial class.

EXAMPLES:

sage: QS2 = SymmetricGroupAlgebra(QQ,2)
sage: b = list(QS2.basis().keys())
sage: b.reverse()
sage: QS2.set_order(b)
sage: QS2.get_order()
[[2, 1], [1, 2]]
sum(operands)

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, [1,2,3,4])
sage: F.sum(F.term(i) for i in [1,2,3])
B[1] + B[2] + B[3]
term(i)

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F.term('a')
B['a']
zero()

EXAMPLES:

sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F.zero()
0
sage.combinat.free_module._divide_if_possible(x, y)

EXAMPLES:

sage: from sage.combinat.free_module import _divide_if_possible
sage: _divide_if_possible(4, 2)
2
sage: _.parent()
Integer Ring
sage: _divide_if_possible(4, 3)
...
ValueError: 4 is not divisible by 3

Previous topic

Combinatorial Algebras

Next topic

Combinatorial Algebras

This Page