Ask Your Question

# 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...

edit retag close merge delete

## 1 Answer

Sort by ยป oldest newest most voted

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

more

## Comments

Hmm. 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.)

( 2012-02-27 20:52:17 +0200 )edit

*grumble grumble*

( 2012-02-27 20:53:31 +0200 )edit

Thank you! Having to check whether a key is contained in monomial_coefficients() before accessing the corresponding coefficient looks like a hack, but it works!

( 2012-02-27 22:10:25 +0200 )edit

@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.

( 2012-02-27 22:13:45 +0200 )edit

No, I get a KeyError.

( 2012-02-27 22:34:56 +0200 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2012-02-27 20:25:45 +0200

Seen: 575 times

Last updated: Feb 28 '12