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']
EXAMPLES:
sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: F == loads(dumps(F))
True
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
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
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]
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
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
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)]
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
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']
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
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
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']
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]
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]
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']
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]
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)
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
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]
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
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
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]
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]
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]
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]
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
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']]
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]]
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']]
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)
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]
EXAMPLES:
sage: XQ = SchubertPolynomialRing(QQ)
sage: XZ = SchubertPolynomialRing(ZZ)
sage: XQ == XZ #indirect doctest
False
sage: XQ == XQ
True
EXAMPLES:
sage: QS3 = SymmetricGroupAlgebra(QQ,3)
sage: print QS3.__repr__()
Symmetric group algebra of order 3 over Rational Field
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
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]
Returns the image of x under the module morphism defined by extending f by linearity.
INPUT:
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
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
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]]
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
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
Returns the order of the elements in the basis.
EXAMPLES:
sage: QS2 = SymmetricGroupAlgebra(QQ,2)
sage: QS2.get_order()
[[1, 2], [2, 1]]
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'
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]]
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]
EXAMPLES:
sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F.term('a')
B['a']
EXAMPLES:
sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'])
sage: F.zero()
0
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