Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I've never used CFM before, so don't take this too seriously, but it looks like the easiest way to get the coefficients of an element expressed in the basis is to convert to a vector, either explicitly or by calling .to_vector():

sage: F = CombinatorialFreeModule(QQ, list('abc'))
sage: B = F.basis()
sage: B
Finite family {'a': B['a'], 'c': B['c'], 'b': B['b']}
sage: z = 13/7 * B['a'] - 9 * B['c']
sage: vector(z)
(13/7, 0, -9)
sage: z.to_vector()
(13/7, 0, -9)
sage: map(parent, vector(z))
[Rational Field, Rational Field, Rational Field]

These coefficients are given in the "right" order, i.e. the order returned by

sage: F.get_order()
['a', 'b', 'c']

I've never used CFM before, so don't take this too seriously, but it looks like the easiest way to get the coefficients of an element expressed in the basis is to convert to a vector, either explicitly or by calling .to_vector():

sage: F = CombinatorialFreeModule(QQ, list('abc'))
sage: B = F.basis()
sage: B
Finite family {'a': B['a'], 'c': B['c'], 'b': B['b']}
sage: z = 13/7 * B['a'] - 9 * B['c']
sage: vector(z)
(13/7, 0, -9)
sage: z.to_vector()
(13/7, 0, -9)
sage: map(parent, vector(z))
[Rational Field, Rational Field, Rational Field]

These coefficients are given in the "right" order, i.e. the order returned by

sage: F.get_order()
['a', 'b', 'c']

Okay, take two. The monomial_coefficients() method lives in the element itself:

sage: MRH([2,3,1])                        
B[[2, 3, 1]]
sage: MRH([2,3,1]).monomial_coefficients()
{[2, 3, 1]: 1}
sage: MRH([2,3,1]).coefficients()         
[1]
sage: MRH([2,3,1]).monomials()   
[B[[2, 3, 1]]]
sage: z = MRH([2,3,1]) + 5*MRH([1,3,2])   
sage: z
5*B[[1, 3, 2]] + B[[2, 3, 1]]
sage: z.monomial_coefficients()
{[2, 3, 1]: 1, [1, 3, 2]: 5}
sage: z.coefficients()                    
[5, 1]         
sage: z.monomials()
[B[[1, 3, 2]], B[[2, 3, 1]]]

I've never used CFM before, so don't take this too seriously, but it looks like the easiest way to get the coefficients of an element expressed in the basis is to convert to a vector, either explicitly or by calling .to_vector():

sage: F = CombinatorialFreeModule(QQ, list('abc'))
sage: B = F.basis()
sage: B
Finite family {'a': B['a'], 'c': B['c'], 'b': B['b']}
sage: z = 13/7 * B['a'] - 9 * B['c']
sage: vector(z)
(13/7, 0, -9)
sage: z.to_vector()
(13/7, 0, -9)
sage: map(parent, vector(z))
[Rational Field, Rational Field, Rational Field]

These coefficients are given in the "right" order, i.e. the order returned by

sage: F.get_order()
['a', 'b', 'c']

Okay, take two. The monomial_coefficients() method lives and other related methods live in the element itself:

sage: MRH([2,3,1])                        
B[[2, 3, 1]]
sage: MRH([2,3,1]).monomial_coefficients()
{[2, 3, 1]: 1}
sage: MRH([2,3,1]).coefficients()         
[1]
sage: MRH([2,3,1]).monomials()   
[B[[2, 3, 1]]]
sage: z = MRH([2,3,1]) + 5*MRH([1,3,2])   
sage: z
5*B[[1, 3, 2]] + B[[2, 3, 1]]
sage: z.monomial_coefficients()
{[2, 3, 1]: 1, [1, 3, 2]: 5}
sage: z.coefficients()                    
[5, 1]         
sage: z.monomials()
[B[[1, 3, 2]], B[[2, 3, 1]]]

I've never used CFM before, so don't take this too seriously, but it looks like the easiest way to get the coefficients of an element expressed in the basis is to convert to a vector, either explicitly or by calling .to_vector():

sage: F = CombinatorialFreeModule(QQ, list('abc'))
sage: B = F.basis()
sage: B
Finite family {'a': B['a'], 'c': B['c'], 'b': B['b']}
sage: z = 13/7 * B['a'] - 9 * B['c']
sage: vector(z)
(13/7, 0, -9)
sage: z.to_vector()
(13/7, 0, -9)
sage: map(parent, vector(z))
[Rational Field, Rational Field, Rational Field]

These coefficients are given in the "right" order, i.e. the order returned by

sage: F.get_order()
['a', 'b', 'c']

Okay, take two. The monomial_coefficients() and other related methods live in the element itself:

sage: MRH([2,3,1])                        
B[[2, 3, 1]]
sage: MRH([2,3,1]).monomial_coefficients()
{[2, 3, 1]: 1}
sage: MRH([2,3,1]).coefficients()         
[1]
sage: MRH([2,3,1]).monomials()   
[B[[2, 3, 1]]]
sage: z = MRH([2,3,1]) + 5*MRH([1,3,2])   
sage: z
5*B[[1, 3, 2]] + B[[2, 3, 1]]
sage: z.monomial_coefficients()
{[2, 3, 1]: 1, [1, 3, 2]: 5}
sage: z.coefficients()                    
[5, 1]         
sage: z.monomials()
[B[[1, 3, 2]], B[[2, 3, 1]]]

[promoted from comments]

There's also .coefficient().