Ask Your Question

darijgrinberg's profile - activity

2020-10-25 12:14:57 +0200 received badge  Famous Question (source)
2019-05-06 12:46:30 +0200 received badge  Famous Question (source)
2017-08-25 21:30:33 +0200 received badge  Notable Question (source)
2016-05-07 02:15:51 +0200 received badge  Notable Question (source)
2016-05-07 02:15:51 +0200 received badge  Popular Question (source)
2015-09-27 02:53:15 +0200 received badge  Popular Question (source)
2014-06-29 03:15:10 +0200 marked best answer What is the name of a tensor product?

I have a tensor like

tensor([a,b,c])

where a, b, c lie in some CombinatorialFreeModule. Where (in Sage syntax) does this tensor lie? (I need to know, because I am writing a function using module_morphism, and it requires me to explicitly specify its codomain.)

Writing

type(tensor([a,b,c]))

doesn't help (it just gives generic trash).

2014-06-29 03:15:10 +0200 marked best answer 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...

2014-06-29 03:14:52 +0200 marked best answer How to make a vector space with basis a *graded* one, and how to do linear algebra on its homogeneous parts?

I was sent here from StackOverflow.

I have a vector space with given basis (it is also a Hopf algebra, but this is not part of the problem). How do I make it into a graded vector space? E. g., I know that in order to make it into an algebra, I have to define a function called product_on_basis somewhere in its definition, and that in order to make it into a coalgebra, I have to define a function called coproduct_on_basis; but what function do I have to define in order to make it into a graded vector space? How can I find out the name of this function? (It is not given in http://www.sagemath.org/doc/reference... . I know the names of the functions for the multiplication and the comultiplication from python2.6/site-packages/sage/categories/examples/hopf_algebras_with_basis.py , but I don't see such a .py file for graded vector spaces.)

Once this is done, I would like to do linear algebra on the graded components. They are each finite-dimensional, with basis a part of the combinatorial basis of the big space, so there shouldn't be any problem. I have defined two maps and want to know, e. g., whether the image of one lies inside the image of the other. Is there an abstract way to do this in Sage or do I have to translate these maps into matrices?

Context (not important): I have (successfully, albeit stupidly) implemented the Malvenuto-Reutenauer Hopf algebra of permutations:

html version resp. sws file

Now I want to check some of its properties. This checking cannot be automated on the whole space, but it is a finite problem on each of its graded components, so I would like to check it, say, on the fifth one.

2014-06-22 07:20:40 +0200 received badge  Famous Question (source)
2014-04-14 10:12:11 +0200 received badge  Notable Question (source)
2013-10-02 02:58:09 +0200 received badge  Popular Question (source)
2012-08-30 12:52:52 +0200 received badge  Taxonomist
2012-03-08 22:43:19 +0200 asked a question Constructor for InfiniteEnumeratedSet?

Imagine I want to rewrite from scratch the "Permutations()" and "Permutations(n)" (for n integer) enumeratedsets and the coercion of the latter into the former. How do I do this?

(This is not the first time I am asking for the constructor of a class. The last time I was looking for the constructor of a graded algebra, and the answer was in some example code. I can't believe there is no documentation for these things!)

PS. I am not really rewriting permutations; I just want to know the constructor so that I can create enumeratedsets similar to permutations (currently, ordered rooted forests a la Loic Foissy).

EDIT: Maybe I should be more concrete. Say I want to encode permutations as n-tuples of integers from {1,2,...,n} for which a certain function returns true. I know how to get the n-tuples of integers from {1,2,...,n}, but I don't even know how to "filter" out the ones for which my function returns false, let alone make them into an EnumeratedSet.

EDIT #2: Thanks to John Palmieri, this question is partially solved: I was able to code the CombinatorialClass of ordered rooted forests on n vertices: HTML file / SWS file. However, I still don't see how to get the CombinatorialClass (or EnumeratedSet or whatever; I don't understand the difference) of all ordered rooted forests, just as there is a class Permutation() of all permutations. This should be as easy as taking a disjoint union, but if I just take DisjointUnionEnumeratedSets(OForestsFamily), then the resulting enumerated set does not know how to test membership (unsurprisingly).

2012-02-28 21:56:48 +0200 marked best answer What is the name of a tensor product?

The tensor should lie in tensor([a,b,c]).parent(), which should be the same as parent(tensor([a,b,c])).

sage: a = SteenrodAlgebra(2).an_element()
sage: M = CombinatorialFreeModule(GF(2), 's,t,u')
sage: s = M.basis()['s']
sage: T = tensor([a,s])
sage: parent(T)
mod 2 Steenrod algebra, milnor basis # Free module generated by s,t,u over Finite Field of size 2            
sage: type(parent(T))
<class 'sage.combinat.free_module.CombinatorialFreeModule_Tensor_with_category'>
2012-02-28 21:56:46 +0200 commented answer What is the name of a tensor product?

It works. Thank you!

2012-02-28 18:30:07 +0200 commented answer What is the name of a tensor product?

Well, I want something that I can use as a codomain for a map. I surely can't write "codomain=mod 2 Steenrod algebra, milnor basis" or "codomain=sage.combinat.free_module.CombinatorialFreeModule_Tensor_with_category".

2012-02-27 23:42:39 +0200 commented answer How to get coordinates of an element of a combinatorial free module?

Ah, that's nice. I was speaking of the monomial_coefficients() hashtable; I didn't notice coefficient(...).

2012-02-27 22:59:17 +0200 commented answer How to get coordinates of an element of a combinatorial free module?

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

2012-02-27 22:37:27 +0200 commented question What is the name of a tensor product?

I have removed the above-linked code, but for what it's worth, it is now part of http://mit.edu/~darij/www/mrh.htm / http://mit.edu/~darij/www/mrh.sws (which is an implementation of the Malvenuto-Reutenauer Hopf algebra).

2012-02-27 22:35:54 +0200 commented answer How to make a vector space with basis a *graded* one, and how to do linear algebra on its homogeneous parts?

Okay, John, thanks - I did it at last. I didn't expect that writing everything as a matrix would be as simple as it turned out to be.

2012-02-27 22:35:28 +0200 marked best answer How to make a vector space with basis a *graded* one, and how to do linear algebra on its homogeneous parts?

You can get some information from the answers to this question.

2012-02-27 22:34:56 +0200 received badge  Commentator
2012-02-27 22:34:56 +0200 commented answer How to get coordinates of an element of a combinatorial free module?

No, I get a KeyError.

2012-02-27 22:10:25 +0200 commented answer How to get coordinates of an element of a combinatorial free module?

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:20 +0200 received badge  Scholar (source)
2012-02-27 22:10:20 +0200 marked best answer How to get coordinates of an element of a combinatorial free module?

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

2012-02-27 21:06:33 +0200 commented question What is the name of a tensor product?

Thanks! At least this part is solved.

2012-02-27 20:55:50 +0200 commented question What is the name of a tensor product?

Ah, thanks. But this creates another problem: "def _repr_(self)" doesn't know what R is. How should I fix the definition of MRHopf?

2012-02-27 20:52:17 +0200 commented answer How to get coordinates of an element of a combinatorial free module?

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