ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 27 Feb 2012 16:42:39 -0600How to get coordinates of an element of a combinatorial free module?https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/This sounds ridiculously simple, but it seems that I don't know the right command. I have an element in a CombinatorialFreeModule, which has a finite basis. I want the coordinates of this vector as an array or a vector or in whatever way. Here is what I have tried:
---------
MRH([1,3,2]) # this is our vector
B[[1, 3, 2]]
for i in MR.homogeneous_component(3).basis():
print(i) # this prints our basis
B[[1, 2, 3]]
B[[1, 3, 2]]
B[[2, 1, 3]]
B[[2, 3, 1]]
B[[3, 1, 2]]
B[[3, 2, 1]]
(MR.homogeneous_component(3)).coordinates(MRH([1,3,2]))
# this should print [0,1,0,0,0,0] or something like this
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_82.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("KE1SLmhvbW9nZW5lb3VzX2NvbXBvbmVudCgzKSkuY29vcmRpbmF0ZXMoTVJIKFsxLDMsMl0pKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpa4FCTA/___code___.py", line 3, in <module>
exec compile(u'(MR.homogeneous_component(_sage_const_3 )).coordinates(MRH([_sage_const_1 ,_sage_const_3 ,_sage_const_2 ]))
File "", line 1, in <module>
File "parent.pyx", line 811, in sage.structure.parent.Parent.__getattr__ (sage/structure/parent.c:6260)
File "parent.pyx", line 323, in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:3110)
AttributeError: 'CombinatorialFreeModule_with_category' object has no attribute 'coordinates'
---------
I have no idea what the error is supposed to tell us, unless the CombinatorialFreeModule type really doesn't have a coordinates function...Mon, 27 Feb 2012 13:25:45 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/Answer by DSM for <p>This sounds ridiculously simple, but it seems that I don't know the right command. I have an element in a CombinatorialFreeModule, which has a finite basis. I want the coordinates of this vector as an array or a vector or in whatever way. Here is what I have tried:</p>
<hr/>
<pre><code>MRH([1,3,2]) # this is our vector
</code></pre>
<p>B[[1, 3, 2]]</p>
<pre><code>for i in MR.homogeneous_component(3).basis():
print(i) # this prints our basis
</code></pre>
<p>B[[1, 2, 3]]</p>
<p>B[[1, 3, 2]]</p>
<p>B[[2, 1, 3]]</p>
<p>B[[2, 3, 1]]</p>
<p>B[[3, 1, 2]]</p>
<p>B[[3, 2, 1]]</p>
<pre><code>(MR.homogeneous_component(3)).coordinates(MRH([1,3,2]))
# this should print [0,1,0,0,0,0] or something like this
</code></pre>
<p>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_82.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -<em>- coding: utf-8 -</em>-\n" + _support_.preparse_worksheet_cell(base64.b64decode("KE1SLmhvbW9nZW5lb3VzX2NvbXBvbmVudCgzKSkuY29vcmRpbmF0ZXMoTVJIKFsxLDMsMl0pKQ=="),globals())+"\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module></p>
<p>File "/tmp/tmpa4FCTA/___code___.py", line 3, in <module>
exec compile(u'(MR.homogeneous_component(_sage_const_3 )).coordinates(MRH([_sage_const_1 ,_sage_const_3 ,_sage_const_2 ]))
File "", line 1, in <module></p>
<p>File "parent.pyx", line 811, in sage.structure.parent.Parent.__getattr__ (sage/structure/parent.c:6260)
File "parent.pyx", line 323, in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:3110)
AttributeError: 'CombinatorialFreeModule_with_category' object has no attribute 'coordinates'</p>
<hr/>
<p>I have no idea what the error is supposed to tell us, unless the CombinatorialFreeModule type really doesn't have a coordinates function...</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?answer=13308#post-id-13308I'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()`.Mon, 27 Feb 2012 13:43:04 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?answer=13308#post-id-13308Comment by darijgrinberg for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20209#post-id-20209Ah, that's nice. I was speaking of the monomial_coefficients() hashtable; I didn't notice coefficient(...).Mon, 27 Feb 2012 16:42:39 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20209#post-id-20209Comment by darijgrinberg for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20217#post-id-20217Thank you! Having to check whether a key is contained in monomial_coefficients() before accessing the corresponding coefficient looks like a hack, but it works!Mon, 27 Feb 2012 15:10:25 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20217#post-id-20217Comment by DSM for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20223#post-id-20223*grumble grumble* Mon, 27 Feb 2012 13:53:31 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20223#post-id-20223Comment by darijgrinberg for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20215#post-id-20215No, I get a KeyError.Mon, 27 Feb 2012 15:34:56 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20215#post-id-20215Comment by darijgrinberg for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20211#post-id-20211My element is MRH([1,3,2]) in the MRH context ( http://mit.edu/~darij/www/mrh.htm ), and I want the Permutation([1,2,3])-th coordinate.Mon, 27 Feb 2012 15:59:17 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20211#post-id-20211Comment by DSM for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20212#post-id-20212What's your element? I just tried it with my above z and it worked fine.Mon, 27 Feb 2012 15:47:17 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20212#post-id-20212Comment by DSM for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20216#post-id-20216@darijgrinberg: you don't need to if you don't want to -- you can call .coefficient([2,1,3]) and get 0, if you like.Mon, 27 Feb 2012 15:13:45 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20216#post-id-20216Comment by darijgrinberg for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20224#post-id-20224Hmm. It seems to timeout and return nothing (and the other variables get uninitialized in the process - as if there was a memory leak). I can kind of understand this, because a priori my vector is in an *infinite*-dimensional free module, and I have no way of telling the "vector" command which submodule I want to consider it as belonging to. (The submodule is formed by part of the basis, so there shouldn't be any problems.)Mon, 27 Feb 2012 13:52:17 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20224#post-id-20224Comment by DSM for <p>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():</p>
<pre><code>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]
</code></pre>
<p>These coefficients are given in the "right" order, i.e. the order returned by</p>
<pre><code>sage: F.get_order()
['a', 'b', 'c']
</code></pre>
<hr/>
<p>Okay, take two. The monomial_coefficients() and other related methods live in the element itself:</p>
<pre><code>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]]]
</code></pre>
<p>[promoted from comments]</p>
<p>There's also <code>.coefficient()</code>.</p>
https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20210#post-id-20210`sage: MRH([1,3,2]).coefficient([1,2,3])` gives `0`. As long as you make the .coefficient() argument a list or an element of Standard permutations (e.g. `MRH([1,3,2]).coefficient(Permutation(MRH([1,2,3])))`, you should be fine. [I just tried it with your current code.]Mon, 27 Feb 2012 16:37:46 -0600https://ask.sagemath.org/question/8751/how-to-get-coordinates-of-an-element-of-a-combinatorial-free-module/?comment=20210#post-id-20210