First time here? Check out the FAQ!

Ask Your Question
1

How to get coordinates of an element of a combinatorial free module?

asked 12 years ago

darijgrinberg gravatar image

updated 12 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 12 years ago

DSM gravatar image

updated 12 years ago

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

Preview: (hide)
link

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

darijgrinberg gravatar imagedarijgrinberg ( 12 years ago )

*grumble grumble*

DSM gravatar imageDSM ( 12 years ago )

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!

darijgrinberg gravatar imagedarijgrinberg ( 12 years ago )

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

DSM gravatar imageDSM ( 12 years ago )

No, I get a KeyError.

darijgrinberg gravatar imagedarijgrinberg ( 12 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 995 times

Last updated: Feb 28 '12