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']
```

2 | No.2 Revision |

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]]]
```

3 | No.3 Revision |

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]]]
```

4 | No.4 Revision |

```
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()`

.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.